zaster
126
4
Laravel

Where clause - undefined variable

Posted 1 month ago by zaster

EDIT: This is what i am trying to achieve

$comp = $sub_jobs->first()->comp;
$last_dispatch = Dispatch::where('no', 'like', '%.'.$comp.'.%')     
->orderBy('id', 'desc')->first();

I am getting null as the result

what i am expecting is an eloquent model

END EDIT

In order to achive the above i have tried the below




$comp = $sub_jobs->first()->comp;

//get the last dispatch_no of that comp
$last_dispatch = Dispatch::where(function($query)
{
 $query->where('no', 'LIKE', '%'.$comp.'%');
})
 ->orderBy('id', 'desc')->first();

I am getting this error

Undefined variable: comp

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.