1 year ago
#296002
json2021
Why do we we pass $request to toArray() if we dont use it?
I am new to Laravel. I am currently building a resource. I was just wondering what is the purpose of passing in the $request object if we use the $this variable when using resources. Below is an example of my code.
class PetitionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return ["id"=> $this->id,"title"=>$this->title,'author'];
}
}
laravel
laravel-request
laravel-resource
0 Answers
Your Answer