dialect/saasify

为 Laravel 模型提供 SaaS 支持

0.1.2 2018-11-01 07:35 UTC

This package is auto-updated.

Last update: 2024-08-29 04:37:24 UTC


README

Build Status

saasify

saasify 帮助将模型打包成模块,以便更容易地进行 SaaS 管理。然后将模块附加到计划中。这使得检查具有特定计划的用户是否能够访问模型成为可能。

安装

待办事项

用法

组件

计划

变量
name, price
关系
modules

 

模块

变量
name
关系
plans, models

模型

变量
model, module, canCreate, canUpdate, canDelete, maxCount
关系
module

示例

 ## Save / Update ##
 
  //You can use the saasify-helper to create components
  $plan = saasify()->plan();
  $model = saasify()->module();
  $model = saasify()->plan();
  
  //Change the variables using the helper methods
  $model = saasify()->model()->setModel(\App\Model::class)->setMaxCount(100);
  
  //Use the save-method to save or update a component
  $plan = saasify()->plan()->setName('foo')->save();
  
  //use the delete-function to remove component
  $plan->delete();
  
  ## Retrieve component ##
  
   $module = saasify()->modules()->find('foobar');
   $modules = saasify()->modules()->all();
   
   //It's also possible to use queries
   $plans = saasify()->plans(function($query){
      return $query->where('price', '>', 10);
   })->get();
   
   //The component-builders also supports
   saasify()->modules()->count();
   saasify()->modules()->first();
   
  
  ## Relations ##
  
   //to add a relaiton use the add-method
   $plan = saasify()->plan()->setName('foo')->save();
   $module = saasify()->module()->setName('bar')->save();
   $plan->addModule($module);
   
   //or remove using the remove-method
   $plan->removeModule($module)
  
   //As of now, you need to set the module on a model before its saved.
   $model = saasify()->model()
                     ->setModel(\App\Model::class)
                     ->setModule($module);
                     
                     
  ## Access ## 
  
  //Add the trait HasPlans to the Laravel model that should have plans
  class User extends Model{
	   use HasPlans;
  }
  
  //this gives acceess to new method
  $user->canAccess(FooBar::class);
  $user->canAccess($fooBar);
  $user->canUpdate(..);
  $user->canDelete(..);
  $user->getCount(..);
  
  //for saasify to know how many instances of a model a user has,
  //add the saasify helper method to the model with the required logic for counting.
  class User extends Model{
	  public static function saasifyCurrent($user){
	    //logic here, example:
	    return $user->foobar()->count();
	  }
  }
  
  

许可证

MIT 许可证 (MIT)。请参阅许可证文件获取更多信息。