我正在開發一個小型個人項目,並且想詢問是否有可能對「verified_employee」的數據庫值運行身份驗證檢查。在我當前的設置中,「verified_employee」是默認設置爲0的布爾數據庫字段。Laravel - 對數據庫電子郵件字段進行身份驗證檢查以進行驗證
我的問題如下: 「刀片視圖內部是否可能(即」Home.blade.php「 )運行一個像「if auth :: user() - > verified_employee ='1'」的檢查,然後讓用戶繼續,如果沒有,調整視圖以便顯示一條消息,意思是「您的帳戶不是由管理團隊激活。請等待他們這樣做」
用戶模式
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Hour;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'admin', 'verified_employee'
];
public function Hours() {
return $this->hasMany(Hour::class);
}
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
查看
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Dashboard</div>
<!-- CHECK IF user->verfied_employee is true -->
<!-- IF YES -->
<div class="panel-body">
Welkom, {{ Auth::user()->name }}
</div>
<!-- IF NO -->
<div class="panel-body">
Please wait till your account has been verified by the team.
</div>
</div>
</div>
</div>
</div>
@endsection
驗證 - >登陸控制器
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
}
什麼是檢查它是1還是0的方法? (考慮到刀片結構看起來像我們只是訪問verified_employee字段) –
@if(Auth :: user() - > verified_employee == 1)檢查1,只是一個常規的語法 –
它做到了。非常感謝你! –