1

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.

Čendi
  • 39
  • 2
  • 13
  • 1
    In your view `{{ route ('admin.view-news',$news->id) }}` you should provide the some id to route – Omar Abdullah Nov 19 '18 at 14:40
  • or compare it with user view – Omar Abdullah Nov 19 '18 at 14:40
  • i did, News:find($id) is not working for some reason, while User::find($id) does work, in show function in both controllers. – Čendi Nov 19 '18 at 15:06
  • Does this answer your question? [Laravel 5.2 Missing required parameters for \[Route: user.profile\] \[URI: user/{nickname}/profile\]](https://stackoverflow.com/questions/35259948/laravel-5-2-missing-required-parameters-for-route-user-profile-uri-user-ni) – miken32 Dec 04 '20 at 03:51

3 Answers3

3

You should try this

{{ route('admin.view-news', $id) }}

Instead of

{{ route('admin.view-news') }}
Kiran Patel
  • 369
  • 1
  • 5
0

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 ]) }}
0

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'));
ganji
  • 752
  • 7
  • 17