Laravel 5身份验证视图

Laravel 5身份验证视图,laravel,view,laravel-authorization,Laravel,View,Laravel Authorization,我正在从事一个Laravel5项目,在html中使用Auth时遇到了一些问题 首先,我将显示我的代码 Routes.php 当你进入mysite/login时,有一个登录表单 当您填写输入并发布时,它将转到LoginController@postLogin 登录控制器 用户模型 当验证尝试为true时,它将转到仪表板。但是我不能在视图中使用auth fascade 仪表板视图 我将得到以下错误: 正在尝试获取非对象视图的属性:C:\xampp\htdocs\laravel5\resources\

我正在从事一个Laravel5项目,在html中使用Auth时遇到了一些问题

首先,我将显示我的代码

Routes.php

当你进入mysite/login时,有一个登录表单 当您填写输入并发布时,它将转到LoginController@postLogin

登录控制器

用户模型

当验证尝试为true时,它将转到仪表板。但是我不能在视图中使用auth fascade

仪表板视图

我将得到以下错误:

正在尝试获取非对象视图的属性:C:\xampp\htdocs\laravel5\resources\views\dashboard\master\dashboard-master.blade.php

如何在我的视图中使用auth?
这是记录应用程序\用户模型的正确方法吗?@HansOtt我添加了我的用户模型我发现了问题所在。Laravel将为用户表使用名为id的主键,但我的主键具有不同的名称。因此,在用户模型中,设置this::public$primaryKey='user_id';知道一切都在起作用
// Router for login
Route::get('/login', ['as' => 'login_path', 'uses' => 'LoginController@getLogin']);
Route::post('/login', ['as' => 'post_login_path', 'uses' => 'LoginController@postLogin']);

// Router for dashboard
Route::get('dashboard', 'DashboardController@index');
public function getLogin()
{
    return view("login.login");
}

public function postLogin(Request $request)
{
    $gebruikersnaam = $request->gebruikersnaam;
    $wachtwoord     = $request->wachtwoord;

    if (Auth::attempt(['gebruikersnaam' => $gebruikersnaam, 'password' => $wachtwoord]))
    {
        //return JsonHandler::createJsonResponse("Successvol ingelogd redirect...", "/dashboard", "success");
        return redirect('/dashboard');
        //return redirect('home');
    }
    else {
        return "fail";
    }

    //dd(Request::input());
    //return $wachtwoord;
}
<?php

namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
    use Authenticatable, CanResetPassword;

    // For custom password field in user table
    public function getAuthPassword()
    {
        return $this->wachtwoord;
    }

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'gebruikersnaam',
        'wachtwoord'
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    //protected $hidden = ['gebruikersnaam', 'wachtwoord'];
}
<p>Welcome {{Auth::user()->gebruikersnaam}}</p>