Ekapp/skolehjem/app/Http/Controllers/rolesController.php

108 lines
2.5 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Spatie\Permission\Models\Role;
class rolesController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$roles = Role::query()->paginate($request->input("limit", 20));
return Response::detect("roles.index", [ "role" => $roles]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return Response::detect("roles.create");
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$requestRole = $request->validate([
"monday" => "required|max:255",
"tuesday" => "required|max:255",
"wednesday" => "required|max:255",
"thursday" => "required|max:255"
]);
$role = new Role($requestRole);
$role->save();
return Response::detect("roles.store");
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
return Response::detect("roles.show", [ "role" => $id]);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$role = Role::find($id);
return Response::detect("roles.edit", ["role" => $role]);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$data = $request->all();
$role = MenuPlan::find($id);
$role->update($data);
$role->save();
return Response::detect("roles.update", [ "role" => $role ]);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$role = MenuPlan::find($id);
$role->delete();
return redirect()->route("roles.index");
}
}