Laravel

class property to eloquent parameter

class FindCustomer extends Component { public string $codbar = '';

public function find(){
$customers = Customer::with('lightbulbs')->whereHas('lightbulbs', function($q) use ($this->codbar){

});
(...)

What I wannt is to pass a parameter to the whereHas function so I don't have to do:

(...)
$codbar = $this->codbar;
$customers = Customer::with('lightbulbs')->whereHas('lightbulbs', function($q) use ($codbar){
(...)

Any help, please?

Alberto.

alberto82230 Member
alberto82230
0
1
257
alberto82230 Member
alberto82230

I found out that $this->codbar is accesible inside anonymous function. It's no necessary to use 'use'.

Thanks anyway.