4 months ago

Where clause - undefined variable

Posted 4 months 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


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.