Here in my controller i have added the EventsResource and at there i have added the with function but in output its not executing or something I can't able to figure out. I have added the output please check. Here is my controller part.
class EventsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
$event = Event::with('eventCategory')->get();
return EventsResource::collection($event);
}
EventsResource
public function toArray($request)
{
return [
'name' => $this->name,
'description' => $this->description,
'image' => $this->image,
'eventcategory' => $this->eventcategory->name,
'start'=> $this->start,
'end'=> $this->end
];
}
public function with($request)
{
return
[
'status' => true,
'message'=> 'sucess'
];
}
output:
{
"name": "Poetry",
"description": "Poetry",
"image": null,
"eventcategory": "Weekend",
"start": "2019-11-12 17:11:00",
"end": "2019-11-26 17:11:00"
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire