简体   繁体   English

Laravel:在 href 中传递 {id}

[英]Laravel: Passing {id} in href

I am trying to pass the user id in the href link as below:-我正在尝试在 href 链接中传递用户 ID,如下所示:-

app.blade.php应用程序.blade.php

<a class="dropdown-item" href="{{route('user.profile', $user->id)}}">Profile </a>

app.php应用程序.php

Route::get('user/profile/{id}', 'UserProfileController@profile')->name('user.profile');

controller UserProfileController.js控制器 UserProfileController.js

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User; 

class UserProfileController extends Controller
{
    //
    public function __construct()
    {
        $this->middleware('auth', ['except' => [ 'profile']]);
    }
    public function profile($id)
    {
        $user = User::find($id);
        return view('user.profile', compact('user') );
    }

}

The Error错误

Undefined variable: user (View: /home/riwaj/Desktop/dmt-intern-manager/InternManager/resources/views/layouts/app.blade.php)未定义变量:用户(视图:/home/riwaj/Desktop/dmt-intern-manager/InternManager/resources/views/layouts/app.blade.php)

错误的SS

您需要隐式声明 id :

<a class="dropdown-item" href="{{route('user.profile', ['id' => $user->id])}}">Profile </a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM