vendredi 15 novembre 2019

how to use laravel resources for relationship both side

i have many to many relationship

category belongstomany jobs
and
job belongstomany categories

i have 2 resource CategoryResources and JobResources

i am did like this

CategoryResources

'name' => $this->name,
'slug' => $this->slug,
'icon' => $this->icon,
'created_at' => $this->created_at->diffForHumans(),
'jobs' => JobResources::collection($this->jobs)

JobResources

'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'description' => $this->description,
'type' => new TypeResources($this->type),
'categories' => CategoryResources::collection($this->categories)
'created_at' => $this->created_at->diffForHumans()

but problem getting is its fetching infinite

how to prevent this

alternative i made different resources like JobReverseResource but its wrong

thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire