'Missing required parameters in route Laravel 5.7
what could be wrong with this:
route
Route::get('admin/view-news/{id}', 'AdminNewsController@show')->name('admin.view-news');
controller
public function index()
{
$news = News::all();
return view('admin.news.news');
}
public function show($id)
{
$news = News::Find($id);
return view('admin.news.view_news')->with('news', $news);
in controller i tried this as well:
`return view('admin.news.view_news', ['news' => News::findOrFail($id)])`;
view
{{ route ('admin.view-news') }}
An important note is, almost the same thing for users is working:
route:
Route::get('/user/{id}', 'UsersController@show');
controller:
public function index()
{
$users = User::orderBy('name', 'asc')->paginate(30);
return view('admin.users.users')->with('users', $users);
}
public function show($id)
{
$user = User::find($id);
return view('admin.users.view_user')->with('user', $user);
}
The error is:
Missing required parameters for [Route: admin.view-news] [URI: admin/view-news/{id}].
What am i missing here, how im not getting the id, and in users controller i do, with almost the same code? Thanks.
Solution 1:[1]
You should try this
{{ route('admin.view-news', $id) }}
Instead of
{{ route('admin.view-news') }}
Solution 2:[2]
This worked for me:
Route::get('admin/view-news/{id?}', 'AdminNewsController@show')->name('admin.view-news');
for the view:
{{ route ('admin.view-news', ['id'=> $id ]) }}
Solution 3:[3]
I found a better solution: In your blade file do like this
<a href="{{route('admin.view-news',"$id")}}">
View
</a>
with this route , in route file
Route::get('admin/view-news/{id}', 'AdminNewsController@show');
$id is sent form your controller with compact
return view('viewPage', compact('id'));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kiran Patel |
| Solution 2 | Ayorinde-codes |
| Solution 3 | ganji |
