I Try To Pass Parameter To With() Function For Model:
Model::with(['functionA($parameters)', 'functionB'])
2
Unfortunately, you can’t use ‘with’ for normal function, it’s used for eloquent’s relationships. for your case you can proceed like this:
$model = new Model(); // or $model = Model::where(anyConditionYouWant)->first(); $model->functionA($parameters);
you can use your functions any time you want without declare them in ‘with’ sentence
I think you are looking for this type.
Model::with(['functionA' => function($query) use ($parameters) { $query->where('some_column', $parameters); }, 'functionB'])->get();
Click here to cancel reply.
2
Answers
Unfortunately, you can’t use ‘with’ for normal function, it’s used for eloquent’s relationships.
for your case you can proceed like this:
you can use your functions any time you want without declare them in ‘with’ sentence
I think you are looking for this type.