本文介绍了尽管在视图中传递了参数,但缺少路由的必需参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到这样的错误:
控制器
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
]);
}
路线
Route::get('/resumenes/{resumen}', 'ResumeneController@show')->name('resumenes.show');
INDEX.BLADE.PHP 在此视图中向我显示错误
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
应该是
<li><a href="{{ route('resumenes.show', $resumen) }}" ><button>Ir</button></a>
推荐答案
看一下您提供的所有代码似乎还不错.
Looking at code you provided everything seems to be fine.
您应该尝试:
php artisan view:clear
确保未使用旧视图.
如果没有帮助,则应运行:
If it won't help, you should run:
php artisan route:list
确保此路由的URL确实看起来像/resumenes/{resumen}
,因为路由定义可能更复杂(使用路由分组),因此完整的URL可能看起来像这样:/something/{something}/resumenes/{resumen}
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}
这篇关于尽管在视图中传递了参数,但缺少路由的必需参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!