【发布时间】:2017-03-14 17:51:21
【问题描述】:
我正在从事一个小型个人项目,我想问一下是否有可能对“verified_employee”的数据库值运行身份验证检查。在我当前的设置中,“verified_employee”是一个布尔数据库字段,默认设置为 0。
我的问题如下: “是否可以在刀片视图(即“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
Auth -> 登录控制器
<?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']);
}
}
【问题讨论】: