I am totally new in laravel. I install laravel 5.2 . I have done with CRUD in laravel. Now i want to integrate laravel authentication package. so i choose zizaco\entrust.
I follow each steps from doc link. but i don't understand what is wrong. In doc there is not mentioned that in which file i have to add following code.
$owner = new Role();
$owner->name = 'owner';
$owner->display_name = 'Project Owner'; // optional
$owner->description = 'User is the owner of a given project'; // optional
$owner->save();
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'User Administrator'; // optional
$admin->description = 'User is allowed to manage and edit other users'; // optional
$admin->save();
and other below code in document.
Even
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
Not mentioned about implements class.
i do
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
but i got error
Trait 'App\Authenticatable' not found
New learner can't get where to place code. i search alot but i can't get perfect document which give right direction.
Where to create role,permissions? Anyone please help me.
After Creating first given process
create roles middleware example CheckRole
<?php
namespace App\Http\Middleware;
use Closure;
class CheckRole
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param $role
* @return mixed
*/
public function handle($request, Closure $next, $role)
{
if (\Auth::user()->hasRole($role)) {
return $next($request);
} else {
return response()->view('errors.401');
}
}
}
now create Check Permission
<?php namespace App\Http\Middleware;
use Closure;
class CheckPermission
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param $permission
* @return mixed
*/
public function handle($request, Closure $next, $permission)
{
if (\Auth::user()->can($permission)) {
return $next($request);
} else {
return response()->view('errors.401');
}
}
}
add these middlewares in kernal.php
'role' => CheckRole::class,
'permission' => CheckPermission::class