[路线:游戏] [URI:游戏/ {type}]缺少必需的参数。 (查看:C:\ xampp \ htdocs \ game \ resources \ views \ header.blade.php)

我是第一次学习Laravel,所以请帮助我,我正在使用Laravel 6 非常感谢enter image description here 我的HTML enter image description here 我的路线 enter image description here

tigergao000 回答:[路线:游戏] [URI:游戏/ {type}]缺少必需的参数。 (查看:C:\ xampp \ htdocs \ game \ resources \ views \ header.blade.php)

编辑您的路线

“ Route :: get('/ game / {type?}','PagesController @ getGame')-> name('game');”

,

您的路线需要一个参数,该参数由{type}定义。 似乎在header.blade.php中,您调用此路由时未传递任何值,因此,您会收到此错误。

,

有很多方法可以检查不为空的变量,

首先,检查您的变量不为空,例如:

@foreach($theloai as $tl)
    @if(isset($tl->idtheloai))
        <div class="icon">      
            <a href="{{route('game',['type'=> $tl->idtheloai]) }}"> <i class="{{$tl->anh}}"></i> <p>{{$tl->tentheloai}}</p> </a>       
        </div>
    @endif 
@endforeach

OR

您可以使用可选参数进行路由:

Route::get('/game/{type?}','PagesController@getGame')->name('game');

我不知道您的控制器逻辑。如果控制器中需要您的type,那么第一个解决方案是好的。

本文链接:https://www.f2er.com/3166746.html

大家都在问