Latest

Thursday, July 6, 2017

Missing required parameters for [Route: homepage.edit] with link in layout

Asked by: GBCrafty


I'm new to Laravel 5.4 and php and I'm having some trouble to do my routing, so I wish you would explain to me what's going on !

I'm developing a back office for my future projects, and for my current project I need to be able to update data sent to the homepage. The edit of the page and the update of the data is now fully functional, I'm just having some trouble to do the link in the layout. Pretty sure it's a trivial problem, yet i'm having trouble figuring it out.

Here is my code :

web.php :

Route::group(['prefix' => 'admin',  'middleware' => 'admin'], function()
{   
  Route::resource('homepage', 'Admin\HomeController');
});

HomeController :`

 public function edit($id) {
    $contentExists = Homepage::first();
    $homepage = Homepage::findOrFail($id);
    return view('admin/homepage/edit', compact('homepage', 'contentExists'));
}`

In the layout :

<ul class="list-unstyled">
 <li>
  <a href="{{ route('homepage.edit') }}">Page d'accueil</a>
 </li>                          
</ul>

Now for that I know I need to pass a parameter to the route, so I did like so :

<ul class="list-unstyled">
 <li>
  <a href="{{ route('homepage.edit', $homepage) }}">Page d'accueil</a>
 </li>                   
</ul>

But then it says the homepage variable is not defined, and I have no idea where I can define this variable since I'm in the layout, and also have no idea what needs to be inside this variable, what's his purpose... Can you help me with that ?



Source

No comments:

Post a Comment

Adbox