Missing required parameter for route although parameter is passed in view

筅森魡賤 提交于 2021-01-29 19:12:03

问题


I got error like this:

Missing required parameters for [Route: resumenes.show] [URI: resumenes/{resumen}]. (View: .../resources/views/resumenes/index.blade.php)

Controller

public function index()
{
    $resumenes = Resumene::orderBy('title','ASC')->paginate();
    return view('resumenes.index', compact('resumenes') );
}

public function show(Resumene $resumen)
{

    return view('resumenes.show', [
        'resumen'=> $resumen
    ]);
}

Routes

 Route::get('/resumenes/{resumen}', 'ResumeneController@show')->name('resumenes.show');

INDEX.BLADE.PHP In this view is where it shows me an error

 @extends('layout')
 @section('title')
 Mis Resumenes
 @endsection

@section('content')
<h1>Mis Resumenes</h1>

@include('partials.sessions')

<a href="{{ route('resumenes.create') }}">Nuevo Resumen</a>
<ul>
    @forelse($resumenes as $resumen)
    <h2>{{ $resumen->title }}</h2>
            **<li><a href="{{ route('resumenes.show', $resumen) }}" ><button>Ir</button></a>** 
            <br> Creado hace {{ $resumen->created_at->diffForHumans() }} </li>
            <hr>
    @empty
            <li>No hay proyectos existentes</li>
    @endforelse
{{ $resumenes->links() }}
</ul>
 @endsection

The error supposed to be in

   <li><a href="{{ route('resumenes.show', $resumen) }}" ><button>Ir</button></a>

回答1:


Looking at code you provided everything seems to be fine.

You should try:

php artisan view:clear

to make sure old view is not used.

If it won't help, you should run:

php artisan route:list

to make sure url for this route really looks like /resumenes/{resumen} because route definittion might be a more complex (using route grouping) so the full url might look like this: /something/{something}/resumenes/{resumen}



来源:https://stackoverflow.com/questions/59472170/missing-required-parameter-for-route-although-parameter-is-passed-in-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!