public function search($input) { $query = Role::query(); $columns = Schema::getColumnListing('roles'); $attributes = array(); foreach ($columns as $attribute) { $attributes[$attribute] = null; if (isset($input[$attribute]) and !empty($input[$attribute])) { $query->where($attribute, $input[$attribute]); $attributes[$attribute] = $input[$attribute]; } } /* ** Filter */ $this->filter($input, $query); /* ** Get count */ $total = $query->count(); /* ** Pagination */ $this->pagination($input, $query); /* ** Order */ $this->order($input, $query); return [$query->get(), $attributes, 'total' => $total]; }
public static function addRole($name, $label = null, $description = null) { $role = Role::query()->where('name', $name)->first(); if (!$role) { $role = new Role(['name' => $name]); } $role->label = $label; $role->description = $description; $role->save(); return $role; }
public function search($input) { $query = Role::query(); $columns = Schema::getColumnListing('roles'); $attributes = array(); foreach ($columns as $attribute) { if (isset($input[$attribute]) and !empty($input[$attribute])) { $query->where($attribute, $input[$attribute]); $attributes[$attribute] = $input[$attribute]; } else { $attributes[$attribute] = null; } } return [$query->get(), $attributes]; }
/** * Index Layout * * @return @Theme View */ public function index() { Meta::title(Lang::get('meta.role')); Meta::meta('description', Lang::get('meta.role description')); $grid = new Grid((new GridConfig())->setDataProvider(new EloquentDataProvider(\App\Models\Role::query()))->setName('grid')->setPageSize(15)->setColumns([(new FieldConfig())->setName('id')->setLabel(Lang::get('label.id'))->setSortable(false)->setSorting(Grid::SORT_ASC), (new FieldConfig())->setName('name')->setLabel(Lang::get('label.name'))->setSortable(true), (new FieldConfig())->setName('description')->setLabel(Lang::get('label.description'))->setSortable(true), (new FieldConfig())->setName('active')->setLabel(Lang::get('label.active'))->setSortable(false)->setCallback(function ($val) { return '<a href="javascript:active(\'' . $val . '\')"><center><i class="fa ' . ($val ? 'fa-check' : 'fa-close') . '"></i></center></a>'; }), (new FieldConfig())->setName('authorize')->setLabel(Lang::get('label.authorize'))->setSortable(false)->setCallback(function ($val) { return '<a href="javascript:active(\'' . $val . '\')"><center><i class="fa ' . ($val ? 'fa-check' : 'fa-close') . '"></i></center></a>'; }), (new FieldConfig())->setName('id')->setLabel(Lang::get('menu.edit'))->setSortable(false)->setCallback(function ($val) { return ' <div class="dropdown"> <button class="btn btn-primary btn-sm dropdown-toggle" type="button" data-toggle="dropdown"> <i class="glyphicon glyphicon-edit"></i> ' . Lang::get('menu.edit') . ' <span class="caret"></span></button> <ul class="dropdown-menu"> <li><a href="' . url('administration/role/form/' . $val) . '"><i class="remove glyphicon glyphicon-edit"></i> ' . Lang::get('menu.edit') . '</a></li> <li><a href="#" class="delete" id="' . $val . '" ><i class="glyphicon glyphicon-trash"></i> ' . Lang::get('menu.remove') . '</a></li> </ul> </div>'; })])); return Theme::view('roles.index', compact('grid', 'text')); }