承接 reivaj86/multiapps 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

reivaj86/multiapps

Composer 安装命令:

composer require reivaj86/multiapps

包简介

A simple Laravel 5 package for handling child-apps within a main-app.

README 文档

README

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)
 .....

...

Installation

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

Configuration file ---- config.php

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.

Usage ---- IsApplUser trait & IsApplUserContract

First of all, include IsApplUser trait and also implement IsApplUserContract inside your Usermodel 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.

Blade Extensions ---- @appl & @uses & @allowedappl

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.

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-06-02