* * @version 1.0.0 */ class MainRoleSkillsController extends VueController { public function __construct() { return $this->vueRoot('admin.mainRoleSkills'); } public function index() { $q = request()->get('q'); $mainRole = mainRole::where('name', 'LIKE', "%{$q}%")->pluck('id'); $skills = Skill::where('name', 'LIKE', "%{$q}%")->pluck('id'); $scores = Score::where('alias', 'LIKE', "%{$q}%")->pluck('id'); $mainRoleSkills = MainRoleSkills::whereIn('main_role_id', $mainRole) ->orWhereIn('skill_id', $skills) ->orWhereIn('scored_id', $scores) ->with([ 'mainRole:id,name,department_id', 'mainRole.department:id,name,description', 'skill:id,name,department_id', 'score:id,alias' ]) ->paginate(config('app.pagination')); return $this->vuew('index', [ 'mainRoleSkills' => $mainRoleSkills ]); } public function create() { $mainRoles = mainRole::with('department:id,name')->orderBy('name', 'ASC')->get(); $skills = Skill::with('department:id,name')->orderBy('name', 'ASC')->get(); $scores = Score::orderBy('alias', 'ASC')->get(); return $this->vuew('create', [ 'mainRoles' => $mainRoles, 'skills' => $skills, 'scores' => $scores ]); } public function store(StoreMainRoleSkills $request) { $create = []; foreach ($request['skills'] as $skill){ $create[] = [ 'main_role_id' => $request['main_role_id'], 'skill_id' => $skill['skill_id'], 'scored_id' => $skill['scored_id'], 'created_at' => now(), 'updated_at' => now(), ]; } MainRoleSkills::insert($create); return $this->index(); } public function update(UpdateMainRoleSkills $request, MainRoleSkills $mainRoleSkills) { $mainRoleSkills->update($request->all()); } public function destroy($id) { $mainRoleSkill = MainRoleSkills::findOrFail($id); $mainRoleSkill->delete(); } }