@jacobkdick did you specified primary key in model
protected $primaryKey = "post_id" // default it look for id
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
When updating my Post model, I run:
$post->title = request('title');
$post->body = request('body');
$post->save();
This does not update my post. But it should according to the Laravel docs on updating Eloquent models. Why is my model not being updated?
Post model:
class Post extends Model
{
protected $fillable = [
'type',
'title',
'body',
'user_id',
];
....
}
Post controller:
public function store($id)
{
$post = Post::findOrFail($id);
// Request validation
if ($post->type == 1) {
// Post type has title
$this->validate(request(), [
'title' => 'required|min:15',
'body' => 'required|min:19',
]);
$post->title = request('title');
$post->body = request('body');
} else {
$this->validate(request(), [
'body' => 'required|min:19',
]);
$post->body = request('body');
}
$post->save();
return redirect('/');
}
Running dd($post->save()) returns true.
Running
$post->save();
$fetchedPost = Post::find($post->id);
dd($fetchedPost);
shows me that $fetchedPost is the same post as before without the updated data.
At first look, all looks good in the code you've shown. Can you also post the form? Maybe you are sending the same value
Here is also what you can do to check it the information is correct
public function store($id)
{
$post = Post::findOrFail($id);
/* check initial data */
dump($post);
// Request validation
if ($post->type == 1) {
// Post type has title
$this->validate(request(), [
'title' => 'required|min:15',
'body' => 'required|min:19',
]);
$post->title = request('title');
$post->body = request('body');
/*check request information */
/*check if the data passed from the form is correct */
dump(request('title'));
dump(request('body'));
/* check updated data */
dump($post);
} else {
$this->validate(request(), [
'body' => 'required|min:19',
]);
/*check request information */
/*check if the data passed from the form is correct */
dump(request('body'));
$post->body = request('body');
/* check updated data */
dump($post);
}
$post->save();
/* stop the flow so you can check the dumps */
die();
return redirect('/');
}
From the above code, you can follow the flow of the update.
Please or to participate in this conversation.