thienkimlove / vauth
Example auth packages
dev-master
2016-04-22 07:34 UTC
Requires
- php: >=5.5.0
This package is auto-updated.
Last update: 2024-11-29 05:14:59 UTC
README
Ved Authorization Package
Install
-
Install fresh version of Laravel 5.2
-
Require package
composer require thienkimlove/vauth:dev-master
-
Add below like to
config/app.php
:
Thienkimlove\Vauth\VauthServiceProvider::class,
-
Run
php artisan vendor:publish --tag="migrations" && php artisan migrate && php artisan make:auth
-
Add in
routes.php
Route::get('example', function () {
return view('vauth::example');
});
//Route::resource('posts', 'PostsController');
Route::get('index_post', '\thienkimlove\vauth\PostsController@index');
Modify app\User.php
:
use Thienkimlove\Vauth\Traits\VauthRoles;
class User extends Authenticatable
{
use VauthRoles;
-
Register one user.
-
Create permission and role and map to user.
php artisan tinker
Psy Shell v0.7.2 (PHP 5.6.11-1ubuntu3.1 — cli) by Justin Hileman
>>>$user = App\User::first();
>>> $permission = new Thienkimlove\Vauth\Models\Permission;
=> Thienkimlove\Vauth\Models\Permission {#652}
>>> $permission->name="index_post";
=> "index_post"
>>> $permission->label="view list post";
=> "view list post"
>>> $permission->save();
=> true
>>> $role = new Thienkimlove\Vauth\Models\Role;
=> Thienkimlove\Vauth\Models\Role {#653}
>>> $role->name="manager";
=> "manager"
>>> $role->label="Manager";
=> "Manager"
>>> $role->save();
=> true
>>> $role->addPermission($permission);
=> null
>>> $user->assignRole('manager');
=> [
"attached" => [
1,
],
"detached" => [],
"updated" => [],
]
>>> exit
- Browser to /example