Returning laravel resource is giving null but the database have files. here is my resource class
class UsersResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'u_id' => $this->user_id,
'u_name' => $this->user_name,
];
}
}
My route file is here
Route::get('test2', function(){
$xyx=Users::find(1);
return new UsersResource($xyx);
});
My response is here as follows
{"data":{"u_id":null,"u_name":null}}
thanks