75 lines
1.6 KiB
PHP
75 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
/**
|
|
* @copyright Copyright (c) 2023 Notsoweb (https://notsoweb.com) - All rights reserved.
|
|
*/
|
|
|
|
use App\Http\Requests\StoreMainRole;
|
|
use App\Http\Requests\UpdateMainRole;
|
|
use App\Models\department;
|
|
use App\Models\mainRole;
|
|
use Illuminate\Http\Request;
|
|
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 MainRoleController extends VueController
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->vueRoot('admin.mainRole');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$q = request()->get('q');
|
|
|
|
$mainRoles = mainRole::orderBy('name', 'ASC')
|
|
->where('name', 'LIKE', "%{$q}%")
|
|
->with('department:id,name')
|
|
->paginate(config('app.pagination'));
|
|
|
|
return $this->vuew('index', [
|
|
'mainRoles' => $mainRoles,
|
|
]);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$department = department::orderBy('name', 'ASC')->get();
|
|
|
|
return $this->vuew('create', [
|
|
'departments' => $department,
|
|
]);
|
|
}
|
|
|
|
public function store(StoreMainRole $request)
|
|
{
|
|
mainRole::create($request->all());
|
|
|
|
return $this->index();
|
|
}
|
|
|
|
public function update(UpdateMainRole $request, mainRole $mainRole)
|
|
{
|
|
$mainRole->update($request->all());
|
|
}
|
|
|
|
public function destroy(mainRole $mainRole)
|
|
{ try{
|
|
$mainRole = mainRole::find($mainRole);
|
|
$mainRole->delete();
|
|
}catch (\Throwable $th) {
|
|
Log::channel('mainRole')->error($th->getMessage());
|
|
}
|
|
}
|
|
}
|