Why do we we pass $request to toArray() if we dont use it?

Viewed 51

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'];
    }
}
0 Answers
Related