In my page, I have the following anchor:
<a href="{{ route('blogtitles.edit', $blogTitle) }}">Edit</a>
which links to the following function in the controller:
public function edit(BlogTitle $blogTitle) { return view('blogtitles.edit')->with('blogTitle', $blogTitle); }
and then the blogtitles/edit.blade.php
file simply contains:
{{ $blogTitle }}
However, in the edit.blade.php
, the variable ‘$blogTitle` is empty, even though I know that it isn’t empty in the original page where it is passed from. Any idea at all what is going wrong? I have other anchors that do exactly the same thing and work fine, so no clue what the problem is.
The url to get to the edit.blade.php
is
http://localhost:8000/blogtitles/1/edit
and the routes are:
PUT|PATCH | blogtitles/{blogtitle} | blogtitles.update | AppHttpControllersBlogTitlesController@update | web | GET|HEAD | blogtitles/{blogtitle}/edit | blogtitles.edit | AppHttpControllersBlogTitlesController@edit | web
Advertisement
Answer
The problem was actually in the function in the controller autogenerated by php artisan
. The $blogTitle
needed to be $blogtitle
so the function became:
public function edit(BlogTitle $blogtitle) { return view('blogtitles.edit')->with('blogTitle', $blogtitle); }
Thanks to user lagbox for prompting me to try this!