doucao1066 2015-11-11 18:28
浏览 22

Laravel路线问题

I have user and I've created a profile button such as each user can look for their data.

In UserController.php I have this function:

/*
* @Get("user/profile/{id}")
*/
public function profile($id)
{
    $user = User::find($id);
    return view('user.profile', ['user' => $user]);
}

I call it from a view like this:

<ul class="dropdown-menu">
    <li>
    <?= link_to('user/profile/'.Auth::user()->id, $title = 'Perfil'); ?>
    </li>
    @if(Auth::user()->type_id == 1)
    <li><a href="{!!URL::to('/user')!!}">Administrar</a></li>
    @endif
    <li role="separator" class="divider"></li>
    <li><a href="{!!URL::to('/logout')!!}"><i class="fa fa-sign-out fa-fw"></i>Logout</a></li>
</ul>

That button takes me to the URL I want such as /user/profile/6 for example, but it sends me this error:

NotFoundHttpException in RouteCollection.php line 161:

  • 写回答

2条回答 默认 最新

  • douzhao7014 2015-11-11 18:43
    关注

    Hard to say where the route is currently going, but I would change the line:

    <li>
    <?= link_to('user/profile/'.Auth::user()->id, $title = 'Perfil'); ?>
    </li>
    

    To the blade version:

    <li><a href="{!! url("/user/profile/".Auth::user()->id) !!}">Profile</a></li>
    

    Also, make sure you have a route that matches it in routes.php:

    Route::get("/user/profile/{id}", "UsersController@profile");
    

    I'm honestly not sure why you're mixing <?= link_to(); ?> and {!! url() !!} blade syntax on the same page... Either way, this should solve your issue.

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制