0

days before i was working on my homework which a problem cause me many days to fix and it was weird for me but somehow I've got that problem again which i'm pretty sure it's about how i name my model when I'm injecting it into function. Here's the full issues

Before when i was going to delete/update data with api i was using :

public function destroy(Event $event, EventGallery $eventGallery)
{

    $eventGallery->delete();
    return response(null,Response::HTTP_NO_CONTENT);
}

And i saw nothing going to happen, then I've changed $eventGallery to $gallery then my problem solved and with this, I've seen this problem was in 2 more functions.

In my Event Model i had relation with gallery name and also it's in protected field, now there's a problem like this again, but it's not working at all, i also had EventVideo $videos and it wasn't working, then i changed it to $video and it worked.

Right now base on above information i need to know why this happen? How changing $eventGallery or $videos to $gallery or $video[related with videos name in Event model and protected with videos fix this?

Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105
Atlas-Pio
  • 1,063
  • 11
  • 26

1 Answers1

2

It is route model binding concept, if your url is

has parameter

{eventGallery}

you have to use

EventGallery $eventGallery

if you want {gallery}

then you need to use

EventGallery $gallery
Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105
  • i had a clue about this, but how about $videos to $video ? in route is videos and i'm using this for spa, `http://127.0.0.1:8000/api/admin/teams/natus-vincere/videos/26` it's `admin/teams/{team}/videos` - $videos wasn't working but $video worked. – Atlas-Pio Jul 09 '19 at 11:58
  • 1
    @Atlas-Pio what ever parameter you are sending in route get that in method and that should work fine, for `admin/teams/{team}/videos` your parameter is `{{team}}` so you should get `$team` in your method and for `http://127.0.0.1:8000/api/admin/teams/natus-vincere/videos/26` what is `26`, check you route parameter name based on that you need to specify the method argument. – Prafulla Kumar Sahu Jul 09 '19 at 12:05