99 lines
2.5 KiB
PHP
99 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
/**
|
|
* @copyright Copyright (c) 2023 Notsoweb (https://notsoweb.com) - All rights reserved.
|
|
*/
|
|
|
|
use App\Http\Requests\StoreMainRoleSkills;
|
|
use App\Http\Requests\UpdateMainRoleSkills;
|
|
use App\Models\mainRole;
|
|
use App\Models\MainRoleSkills;
|
|
use App\Models\Score;
|
|
use App\Models\Skill;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Notsoweb\Core\Http\Controllers\VueController;
|
|
|
|
/**
|
|
* Descripción
|
|
*
|
|
* @author Moisés de Jesús Cortés Castellanos <ing.moisesdejesuscortesc@notsoweb.com>
|
|
*
|
|
* @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();
|
|
}
|
|
|
|
}
|