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

276 Views Asked by At

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

There are 0 best solutions below