bantenprov / advancetrust
Laravel package untuk mengolah role / hak akses pengguna aplikasi
Requires
- php: ~5.6|~7.0
- bantenprov/laravel-api-manager: ^1.0
- guzzlehttp/guzzle: ^6.3
- illuminate/support: ~5.1
- laravelcollective/html: ^5.4.0
- santigarcor/laratrust: 5.0.*
- that0n3guy/transliteration: 2.0.x
Requires (Dev)
- phpunit/phpunit: >=5.4.3
- squizlabs/php_codesniffer: ^2.3
This package is not auto-updated.
Last update: 2024-11-10 04:58:35 UTC
README
This package inspired and extend the .
DEMO
Demo for this package is available here Role
Version
Install
-
Advancetrust for laravel :
composer require bantenprov/advancetrust "1.0.1"
-
Advancetrust for laravel with vue js :
composer require bantenprov/advancetrust "1.0.2"
-
Advancetrust available API request :
composer require bantenprov/advancetrust "1.0.3"
1. In your config/app.php add for laravel <= 5.4 only:
'providers' => array( App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, ... Bantenprov\Advancetrust\advancetrustServiceProvider::class, Bantenprov\LaravelApiManager\LaravelApiManagerServiceProvider::class, Laratrust\LaratrustServiceProvider::class, Collective\Html\HtmlServiceProvider::class, 'That0n3guy\Transliteration\TransliterationServiceProvider', ),
'aliases' => [ 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, ... 'Laratrust' => Laratrust\LaratrustFacade::class, 'Form' => Collective\Html\FormFacade::class, 'Html' => Collective\Html\HtmlFacade::class,
2. php artisan
$ php artisan vendor:publish --tag="laratrust"
$ php artisan vendor:publish
$ php artisan laratrust:setup
$ php artisan laratrust:seeder
$ php artisan laravel-api-manager:add-route
$ php artisan migrate
$ composer dump-autoload
$ php artisan db:seed --class=LaratrustSeeder
$ php artisan serve
Please run this available command after finished installation
$ php artisan advancetrust:add-route $ php artisan advancetrust:create-controller $ php artisan advancetrust:create-view $ php artisan advancetrust:version
Add authentication to use the package
$ php artisan make:auth
Edit resources/views/home.blade.php
@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> <div class="panel-body"> @if (session('status')) <div class="alert alert-success"> {{ session('status') }} </div> @endif {{-- add menu content here --}} @yield('advancetrust_content') </div> </div> </div> </div> </div> @endsection
Server config
Tambahkan pada .env anda parameter berikut
- Host yang digunakan sebagai role controller sebagai eksekutor penambahan role
BANTENPROV_ROLEHOST=rolehost.domain.tld
setting ini harus digunakan pada semua site yang menggunakan advantrust.
- Host yang digunakan sebagai requestor penambahan role
BANTENPROV_DRIVERHOST=driverhost.domain.tld
Contoh penggunaan
Request menggunakan guzzle pada client
Request menggunakan package guzzle
caranya install terlebih dahulu package guzzle dengan cara :
composer require guzzlehttp/guzzle
pada client tambahkan BANTENPROV_ROLEHOST=http://localhost:8000
pada file .env
Host yang digunakan sebagai role controller sebagai eksekutor penambahan role
pada contoh di atas menggunakan http://localhost:8000
sebagai host
// method get Route::get('/guzzle/permission/get',function(){ $hostname = \Request::root(); $client = new GuzzleHttp\Client(['base_uri' => env('BANTENPROV_ROLEHOST').'/api/v1/advancetrust/']); $response = $client->request('GET', 'permission',[ 'headers' => [ 'secret_key' => 'QwQjR4V8VKXqvWR3l7v056VU9l2d2JKkcXvM9GQKYhn8J5gsGKNdEYj6cHaoP5HOne51TwSRk4CT0ksZjCUCEEKi6V1a34bQqXEI', 'client' => $hostname ] ]); return $response->getBody(); }); Route::get('/guzzle/role/get',function(){ $hostname = \Request::root(); $client = new GuzzleHttp\Client(['base_uri' => env('BANTENPROV_ROLEHOST').'/api/v1/advancetrust/']); $response = $client->request('GET', 'role',[ 'headers' => [ 'secret_key' => 'QwQjR4V8VKXqvWR3l7v056VU9l2d2JKkcXvM9GQKYhn8J5gsGKNdEYj6cHaoP5HOne51TwSRk4CT0ksZjCUCEEKi6V1a34bQqXEI', 'client' => $hostname ] ]); return $response->getBody(); }); //method post Route::get('/guzzle/permission/post',function(){ $hostname = \Request::root(); $client = new GuzzleHttp\Client(['base_uri' => env('BANTENPROV_ROLEHOST').'/api/v1/advancetrust/']); $response = $client->request('POST', 'permission/store',[ 'headers' => [ 'secret_key' => 'QwQjR4V8VKXqvWR3l7v056VU9l2d2JKkcXvM9GQKYhn8J5gsGKNdEYj6cHaoP5HOne51TwSRk4CT0ksZjCUCEEKi6V1a34bQqXEI', 'client' => $hostname ], 'form_params' => [ 'name' => 'example name', 'description' => 'example description', 'display_name' => 'example display name' ] ]); return $response->getBody(); }); Route::get('/guzzle/role/post',function(){ $hostname = \Request::root(); $client = new GuzzleHttp\Client(['base_uri' => env('BANTENPROV_ROLEHOST').'/api/v1/advancetrust/']); $response = $client->request('POST', 'role/store',[ 'headers' => [ 'secret_key' => 'QwQjR4V8VKXqvWR3l7v056VU9l2d2JKkcXvM9GQKYhn8J5gsGKNdEYj6cHaoP5HOne51TwSRk4CT0ksZjCUCEEKi6V1a34bQqXEI', 'client' => $hostname ], 'form_params' => [ 'name' => 'example name', 'description' => 'example description', 'display_name' => 'example display name' ] ]); return $response->getBody(); });
secret key secret_key
ini dibuat menggunakan package laravel-api-manager
, caranya akses pada browser : http://localhost:8000/api_manager
dan tambahkan data baru.
client : localhost:9090
description : cient
setelah berhasil di tambahkan
gunakan api keys
untuk pada value secret_key
pada header
'secret_key' => 'api_keys'
Pada host tambahkan BANTENPROV_DRIVERHOST=http://localhost:9090
pada file .env
Host yang digunakan sebagai requestor penambahan role
jadi pada contoh ini host yang diberi hak akses untuk melakukan penambahan data baru sesuai dengan BANTENPROV_DRIVERHOST
yaitu http://localhost:9090
dan selain dari http://localhost:9090
hanya mempunyai hak akses untuk meminta data dari http://localhost:8000
command run server pada client :
$ php artisan serve --port=9090
command run server pada host :
$ php artisan serve
jika masih binggung untuk cara penggunaan
guzzle
silahkan baca-baca dokumentasinya disini
The MIT License (MIT). Please see License File for more information.