Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Rumnaz khan's avatar

Find function in API not working

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.

0 likes
10 replies
Sinnbeck's avatar

So there is no transaction with that ID?

You can ensure that it fails

$transaction = Transaction::findOrFail($id); 
Sinnbeck's avatar

@Rumnaz khan can you show dd($id); and the model and the entry in the database?

Sinnbeck's avatar

@Rumnaz khan and dd($id);?

Edit : oh that is the first image.. So 5. Does anything change if you remove the multi tenent trait?

tykus's avatar

@Rumnaz khan does that trait have a global scope that is applying to team_id or user_id???

You have the id but probably not scopes to the current user/team?

Rumnaz khan's avatar

@Sinnbeck removing multi tenant trait does not change anything. but somehow @tykus's answer worked . not still sure what was the problem with my code though.

Sinnbeck's avatar

@Rumnaz khan use debugbar to check the query being run. Most like something is adding to your query. I suggest looking into it, as not being able to get a transaction by id is quite bad

tykus's avatar
tykus
Best Answer
Level 104

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.