Package Data | |
---|---|
Maintainer Username: | reivaj86 |
Maintainer Contact: | reivaj_86@hotmail.com (reivaj86) |
Package Create Date: | 2015-06-02 |
Package Last Update: | 2015-08-17 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-12-23 03:18:44 |
Package Statistics | |
---|---|
Total Downloads: | 13 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Simple Laravel 5 package for handling access to child-applications (Appls) within a main-application. Each Appl can be seen as a Moudle or Package within the Main APP. With this package you can grant or ungrant access to every single application, attaching or dettaching appls from a user.
Main App. //with 2 child apps
-->Appl_1. (Module 1)
-->Appl_2. (Module 2)
.....
...
Pull this package through Composer. ---- composer.json
{
"require": {
"reivaj86/multiapps": "dev-master"
}
}
Run $ composer update
Add the package to your application service providers in: config/app.php
'providers' => [
'Illuminate\Foundation\Providers\ArtisanServiceProvider',
'Illuminate\Auth\AuthServiceProvider',
...
'Reivaj86\Multiapps\MultiappsServiceProvider',
],
Publish the package migrations. Publish config file to your application.
$ php artisan vendor:publish --provider="Vendor/Reivaj86/Multiapps/MultiappsServiceProvider" --tag="config"
$ php artisan vendor:publish --provider="Vendor/Reivaj86/Multiapps/MultiappsServiceProvider" --tag="migrations"
Run migrations.
$ php artisan migrate
Crate your seeds // optional Run the seeder
You can change the connection for your models, slug separator and there is also a very userfull purport option. View the config file for more information.
First of all, include IsApplUser
trait and also implement IsApplUserContract
inside your User
model or Custom
model.
use Reivaj86\Multiapps\Contracts\IsApplUserContract;
use Reivaj86\Multiapps\Traits\IsApplUser;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, IsApplUserContract {
use Authenticatable, CanResetPassword, IsUserAppl;
Done!. You can create your first appl and attach it to a User or Custom Model
use Reivaj86\Multiapps\Models\Appl;
use App\User;
$appl = Appl::create([
'name' => 'Child_App_Name',
'slug' => 'child_app_slug',
'description' => '' // optional
]);
$user = User::find($id)->attachAppl($appl); // you can pass whole object, or just id
You can easily check if the current user uses a child_app.
if ($user->uses('child_app')) // you can pass an id or slug
{
return 'child_app_slug';
}
You can also do the following:
if ($user->usesChild_App_Name())
{
return 'child_app_slug';
}
And also, there is a way to check if a User/Model has access to multiple appls:
if ($user->can('child_app_1|child_app_2')) // or $user->can('child_app_1, child_app_2') and also $user->can(['child_app_1', 'child_app_2'])
{
// if user has at least one appl
}
if ($user->can('child_app_1|child_app_2', 'All')) // or $user->can('child_app_1, child_app_2', 'All') and also $user->can(['child_app_1', 'child_app_2'], 'All')
{
// if user has all appls
}
When you are creating appls, there is also optional parameter level
. It is set to 1
by default, but you can overwrite it and then you can do something like this:
if ($user->level() > 3)
{
// code
}
This option is very usefull when you want to set access levels to every child app. You can easily integrate this with a Role and level authentication package.
If user has multiple child apps, the method level
returns the leve for that appl. For a basic User it shall always be 1.
There are three Blade extensions. Basically, it is replacement for classic if statements.
@appl('child_app_slug') // @if(Auth::check() && Auth::user()->uses('child_app_slug'))
// user can use child_app_slug
@endappl
@allowedappl('child_app_slug', $view) // @if(Auth::check() && Auth::user()->allowed('child_app', $view))
// show child_app specific content // Access to specific content within the child_app
@endallowedappl
@appl('child_app_1|child_app_2', 'all') // @if(Auth::check() && Auth::user()->can('child_app_1|child_app_2', 'all'))
// user can use child_app_1 and also child_app_2
@else
// something else
@endappl
For a better understanding, please have a look at IsApplUserContract.