Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 5.2中RouteCollection.php第161行中的NotFoundHttpException_Php_Laravel 5.2 - Fatal编程技术网

Laravel 5.2中RouteCollection.php第161行中的NotFoundHttpException

Laravel 5.2中RouteCollection.php第161行中的NotFoundHttpException,php,laravel-5.2,Php,Laravel 5.2,我的路线: Route::get('/user/{username}'[ '使用'=>'\MostWanted\Http\Controllers\ProfileController@getProfile', '作为'=>'profile.index', ]); 我的控制器: namespace MostWanted\Http\Controllers; use MostWanted\Models\User; use Illuminate\Http\Request; class ProfileC

我的路线:
Route::get('/user/{username}'[
'使用'=>'\MostWanted\Http\Controllers\ProfileController@getProfile',
'作为'=>'profile.index',
]);

我的控制器:

namespace MostWanted\Http\Controllers;

use MostWanted\Models\User;
use Illuminate\Http\Request;

class ProfileController extends Controller
{
    public function getProfile($username)
    {

        $user = User::where('username', $username)->first();

        if (!$user) {
            abort(404);
        }

        return view('profile.index');

    }
}
查看内容:

@extends('templates.default')

@section('content')


    <div class="row">
            <div class="col-lg-5">
                <!-- User information and statuses -->
            </div>
            <div class="col-lg-4 col-lg-offset-3">
                <!-- Friends, friend requests -->
            </div>
        </div>

@stop
@extends('templates.default')
@节(“内容”)
@停止
我很确定代码是正确的,但它仍然有这个错误。问题在哪里?我如何解决


感谢您提前提供帮助。

您确认数据库中存在用户名了吗

$user = User::where('username', $username)->first();
if (!$user) {
    return 'User does not exists';
}
带有中止(404)的代码可以替换为

$user = User::where('username', $username)->firstOrFail();

您是否确认数据库中存在用户名

$user = User::where('username', $username)->first();
if (!$user) {
    return 'User does not exists';
}
带有中止(404)的代码可以替换为

$user = User::where('username', $username)->firstOrFail();

是的。迁移表中存在用户名。Schema::create('users',function(Blueprint$table){$table->increments('id');$table->string('username');$table->string('last_name');$table->string('email');$table->string('first_name')->nullable();$table->string('location')->nullable();$table->string('memory_token;$table->timestamps();});}否,假设url如下:/user/admin=>数据库中是否已经存在用户名admin?否。可能不存在。我目前正在使用Windows 10。有什么方法可以访问数据库吗?如果是这样,怎么做?我发现它存在,但当我点击链接时,它不知怎么地不会显示出来,但是当我在链接中手动添加{username}时,它会显示出来。是的。迁移表中存在用户名。Schema::create('users',function(Blueprint$table){$table->increments('id');$table->string('username');$table->string('last_name');$table->string('email');$table->string('first_name')->nullable();$table->string('location')->nullable();$table->string('memory_token;$table->timestamps();});}否,假设url如下:/user/admin=>数据库中是否已经存在用户名admin?否。可能不存在。我目前正在使用Windows 10。有什么方法可以访问数据库吗?如果是这样,怎么做?我发现它存在,但当我点击链接时,它不知怎的不会显示出来,但是当我在链接中手动添加{username}时,它会显示出来。请看一下这个答案,它可能会有帮助请看一下这个答案,它可能会有帮助