app/Http/Resources/UserResource.php
/**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
Transform the resource into an array.
Transform the resource into an array .
public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'email' => $this->email,
            'email_verified_at' => $this->email_verified_at,
            'role' => count($this->getRoles()) > 0 ? $this->getRoles()[0] : null,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
public function toArray ( $ request ) { return [ 'id' => $ this -> id , 'name' => $ this -> name , 'email' => $ this -> email , 'email_verified_at' => $ this -> email_verified_at , 'role' => count ( $ this -> getRoles ( ) ) > 0 ? $ this -> getRoles ( ) [ 0 ] : null , 'created_at' => $ this -> created_at , 'updated_at' => $ this -> updated_at , ] ; }
Transform the resource into an array.
Transform the resource into an array .
// getRoles (laratrust) return array of roles assigned to user and we will restrict one role per user // hence picking first element