Laravel Argument 1传递了字符串

时间:2015-06-13 15:09:17

标签: php laravel laravel-5

所以这是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之类的东西时,我总会得到那个错误。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

尝试:

public function index($username) {
    $user = User::where('username', '=', $username)->first();

    return view('auth.welcome', compact('user'));

}