So there is no transaction with that ID?
You can ensure that it fails
$transaction = Transaction::findOrFail($id);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a post api call in laravel that will update only one field in the table
public function redeem($id) {
$transaction = Transaction::find($id);
dd($transaction);
$transaction->redeem = true;
$transaction->save();
}
if I dd $id it is showing result but find function is not working transaction is showing null. N.B : id is the primary key.
You have no record with the given ID.
You could write all of this functionality in a single line:
public function redeem($id)
{
Transaction::where('id', $id)->update(['redeem' => true]);
}
Please or to participate in this conversation.