【问题标题】:Route [user.profile] not defined. Laravel 5.3路由 [user.profile] 未定义。拉拉维尔 5.3
【发布时间】:2017-03-16 16:21:35
【问题描述】:

我想进入个人资料页面,但未定义错误路线。我尝试定义路线但仍然存在 我在 User resourceController 中定义了一个新函数作为配置文件 我正在以这种方式定义我的路线

Route::get('user/profile', 'UserController@profile');
Route::resource('/user', 'UserController');

这是我的标题,我将通过它进入个人资料页面

                    <li>
                        <a href="{{route('user.profile')}}">
                            <i class="icon-user"></i> My Profile </a>
                    </li>

这里 User 是文件夹的名称,profile 是其中的页面

这是 UserController

中的方法
public function profile($request)
    {
        return ('Here');
        return view('user.profile');
    }

我正在测试,但它没有进入配置文件方法

【问题讨论】:

    标签: php laravel routes


    【解决方案1】:

    您正在尝试使用命名路由,因此您需要set a name

    Route::get('user/profile', ['as' => 'user.profile', 'uses' => 'UserController@profile']);
    

    或者:

    Route::get('user/profile', 'UserController@profile')->name('user.profile');
    

    如果不想使用命名路由,可以使用url()代替route()

    <a href="{{ url('user/profile') }}">
    

    【讨论】:

    • 还有一件事,请问我如何在此处通过 url 或路由传递用户 ID @Alexey Mezenin
    • @recoverymen,你应该使用route parameters。但是在这种情况下,如果您想获取经过身份验证的用户的 ID,只需使用auth()-&gt;user()-&gt;id,它将始终返回当前登录用户的 ID。
    猜你喜欢
    • 1970-01-01
    • 2019-05-26
    • 2018-10-14
    • 1970-01-01
    • 2014-10-24
    • 2021-08-14
    • 2019-01-01
    • 2019-09-09
    • 2021-12-30
    相关资源
    最近更新 更多