php - Lavavel Undefined Variable in ::find() when editing existing posts
Solution:
If $title variable is contains notVariable that make $posts->$title equivalen to $posts->notVariable. So you just need to remove $ on $posts key/attribute.
change
$posts->$title = $title;
Log::info($posts);
$posts->$slug = $request->input('pxp-submit-comm-slug');
$posts->$content = $overview;
$posts->$featured_url = $photo;
$posts->$post_status = $post_status;
to
$posts->title = $title;
Log::info($posts);
$posts->slug = $request->input('pxp-submit-comm-slug');
$posts->content = $overview;
$posts->featured_url = $photo;
$posts->post_status = $post_status;
Answer
Solution:
PHP allows for the use of variable variables as well as using variables as object keys (see this post for more explanation). You appear to be unintentionally incorporating this principle.
Before the Log::info() statement you are setting
$posts->$title = $title
In PHP this is actually setting the key as $titles value which explains the "Two Homes NOW Under Construction for Late Spring Move-in Dates" key in your object. You aren't getting an Undefined variable error for $title because that variable exists. You are getting the Undefined variable: slug error because you are attempting to use the variables $slug, $content, etc. which do not exist to set the other keys. You need to update your code to remove the $ after the arrow.
$posts->title = $title;
$posts->slug = $request->input('pxp-submit-comm-slug');
$posts->content = $overview;
$posts->featured_url = $photo;
$posts->post_status = $post_status;
Source