## 基礎數據設置
>[info] 功能:
1,顯示數據:查詢 `roles` 角色表 顯示角色
/**
* @desc 列表頁數據顯示
*
*/
public function index(){
return view('roles_list');
}
/**
* @desc ajax列表搜索
*
*/
public function ajax(){
//分頁
$data = [];
$model = model::DefaultWhere()->paginate(config('app.page_size'));
//設置當前分頁中的URL路徑
$model->setPath(url(url_string()) );
$data['model'] = $model;
$output['html'] = view('roles_ajax',$data);
echo json_encode(['status'=>true,'html'=>$output['html'],'render'=>'ajax_load_table']);
exit;
}
>[info] 2,插入數據:新建角色 ,編輯數據:修改角色信息
/*
* @desc 保存表單數據
*
*/
static function saveForm(){
$data = post_data();
if($data['id']){
$data['updated'] = time();
$model = self::find($data['id']);
$roles_id = $model->role_users->toArray();
if($roles_id){
exit(json_encode(['status'=>0,'msg'=>__('門店角色已被使用,無法進行刪除或者修改')]));
}
}else{
$slug = self::where('slug','=',$data['slug'])->first()->slug;
if($slug){
exit(json_encode(['status'=>0,'msg'=>__('唯一標識不能重復')]));
}
$data['created'] = time();
$model = new self;
}
$model->data($data)->save();
}
>[info]3,刪除數據:刪除角色 如果此角色正在使用則不能刪除
/*
* @desc 刪除表單數據
*/
static function deleteForm($id){
$roles_id = role_users::where('role_id',$id)->first();
if($roles_id){
return 1;
}else{
$model = self::where('id',$id);
$model->delete();
}
}
>[info]4,關聯`role_users` 員工賬號表
/*
*@desc 關聯role_users
*
*/
public function role_users(){
return $this->hasMany('models\role_users','role_id');
}