I have two protected areas in one application, but only admin can enter both areas of the user (Admin) and the employee. Please give me a suggestion on my question.
routes.php
Route::get('employee/login', array(
'uses' => 'LoginController@create',
'as' => 'login.create'
));
Route::post('employee/login', array(
'uses' => 'LoginController@store',
'as' => 'login.store'
));
LoginController.php
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use View;
use Illuminate\Http\Request;
use Input;
use Auth;
use Config;
use Redirect;
use App\Employee;
use DB;
use Validator;
class LoginController extends Controller {
public function __construct()
{
Config::set('auth.model', 'Employee');
Config::set('session.path', '/employee');
}
public function create()
{
return View::make('employee.login');
}
public function store()
{
if(Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password'))))
{
return Redirect::intended('employee/home');
}
return Redirect::route('login.create')
->withInput()
->with('login_errors', true);
}
public function destroy()
{
Log::logout();
return View::make('employee.destroy');
}
}
Login.blade.php
<html>
<head>
<link href='css/style.css' rel='stylesheet' type='text/css'>
<link href='../css/style.css' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="head_text">
<h2 style="text-align:center;">Employee Login</h2>
</div>
<div class="login_table">
{!! Form::open(array('route' => 'login.store')) !!}
<h1 style="text-align:center;">Login</h1>
<p>
{!! $errors->first('email') !!}
{!! $errors->first('password') !!}
</p>
<p>
{!! Form::label('email', 'Email Address') !!}
{!! Form::text('email', Input::old('email'), array('placeholder' => 'awesome@awesome.com')) !!}
</p>
<p>
{!! Form::label('password', 'Password') !!}
{!! Form::password('password') !!}
</p>
<p>
{!! Form::submit('Login') !!}
</p>
{!! Form::close() !!}
</div>
</body>
</html>
Employee (model)
<?php namespace App\Models;;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticable;
use Illuminate\Auth\Authenticable as AuthenticableTrait;
use Illuminate\Support\Facades\Auth;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class Employee extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
protected $table = 'employee';
protected $fillable = [
'firstname',
'lastname',
'email',
'birthdate',
'address',
'phone',
'mobileno',
'employeetype',
'partment',
'uniqueemployeeid',
'password',
'repassword'
];
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
public function setPasswordAttrribute($password)
{
$this->attributes['password']=Hash::make($password);
}
public static $rules = array(
'firstname' => 'required',
'lastname' => 'required',
'email' => 'required|email',
'birthdate' => 'required',
'address' => 'required',
'phone' => 'required',
'mobileno' => 'required',
'employeetype' => 'required',
'department' => 'required',
'uniqueemployeeid' => 'required',
'password' => 'required',
'repassword' => 'required|same:password'
);
public function getFullName()
{
return $this->firstname ;
}
}
auth.php
<?php
return [
'driver' => 'eloquent',
'model' => 'App\User',
'model' => 'App\Employee',
'table' => 'users',
'table' => 'employee',
'password' => [
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
],
];