Pass id parameter to resource in Laravel
I have the following method in my Laravel controller:
public function specialOffers($id) {
return AppHttpResourcesSpecialOfferResource::collection(Offers::all());
}
I need some special manipulations, so I’ve created this SpecialOfferResource resource. The resource code is:
class SpecialOfferResource extends Resource {
/**
* Transform the resource into an array.
*
* @param IlluminateHttpRequest $request
* @return array
*/
public function toArray($request) {
//here I need the $id passed to the controller's method,
//but I only have $request
return [
//my request fields, everything ok
];
}
}
How can I pass $id from the controller’s method to this resource? I know I can pass through the request as a field, but is it possible this other way?
from Laravel Questions and Answers https://laravelquestions.com/php/pass-id-parameter-to-resource-in-laravel/
via Lzo Media
No comments:
Post a Comment