所以这是2小时,我仍然无法让我的应用程序工作。我收到错误异常Argument 1 passed to App\Http\Controllers\ProgramController::index() must be an instance of App\User, string given
。这是我的路线:
$app->bind('user', function($value, $route) {
return User::findOrFail($value);
});
$app->get('program/profile/{user}', 'App\Http\Controllers\ProgramController@index');
在我的控制器中:
public function index(User $user) {
return view('auth.welcome', compact('user'));
}
每当我运行像http://localhost:8000/program/profile/username
之类的东西时,我总会得到那个错误。有什么想法吗?
答案 0 :(得分:1)
尝试:
public function index($username) {
$user = User::where('username', '=', $username)->first();
return view('auth.welcome', compact('user'));
}