[英]Laravel: Passing {id} in href
我正在嘗試在 href 鏈接中傳遞用戶 ID,如下所示:-
應用程序.blade.php
<a class="dropdown-item" href="{{route('user.profile', $user->id)}}">Profile </a>
應用程序.php
Route::get('user/profile/{id}', 'UserProfileController@profile')->name('user.profile');
控制器 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') );
}
}
錯誤
未定義變量:用戶(視圖:/home/riwaj/Desktop/dmt-intern-manager/InternManager/resources/views/layouts/app.blade.php)
您需要隱式聲明 id :
<a class="dropdown-item" href="{{route('user.profile', ['id' => $user->id])}}">Profile </a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.