2020-06-09 07:05:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2020-06-24 06:23:15 +00:00
|
|
|
use Illuminate\Http\Response;
|
2020-06-25 09:19:51 +00:00
|
|
|
use Spatie\Permission\Models\Permission;
|
2020-06-09 07:05:07 +00:00
|
|
|
|
|
|
|
class PermissionController extends Controller
|
|
|
|
{
|
2020-08-06 13:31:38 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware(["auth"]);
|
|
|
|
$this->middleware(["lang"]);
|
|
|
|
}
|
|
|
|
|
2020-06-09 07:05:07 +00:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
2020-06-25 09:19:51 +00:00
|
|
|
* @param Request $request
|
|
|
|
* @return Response
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
2020-06-25 09:19:51 +00:00
|
|
|
public function index(Request $request)
|
2020-06-09 07:05:07 +00:00
|
|
|
{
|
2020-09-22 08:45:27 +00:00
|
|
|
$permission = Permission::query()->get();
|
2020-06-25 09:19:51 +00:00
|
|
|
|
|
|
|
return Response::detect("permission.index", [ "permission" => $permission ]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2020-06-25 09:19:51 +00:00
|
|
|
* @return Response
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2020-06-25 09:19:51 +00:00
|
|
|
return Response::detect("permission.create");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2020-06-25 09:19:51 +00:00
|
|
|
* @param Request $request
|
|
|
|
* @return Response
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2020-06-25 09:19:51 +00:00
|
|
|
$requestBody = $request->validate([
|
|
|
|
"name" => "required|max:255",
|
|
|
|
"link" => "required|max:255"
|
|
|
|
]);
|
|
|
|
|
|
|
|
$permission = new Permission($requestBody);
|
|
|
|
$permission->save();
|
|
|
|
|
|
|
|
return Response::detect("permission.store");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
2020-06-25 09:19:51 +00:00
|
|
|
* @return Response
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
2020-06-25 09:19:51 +00:00
|
|
|
return Response::detect("permission.show", [ "permission" => $id]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
2020-06-25 09:19:51 +00:00
|
|
|
* @return Response
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
2020-06-25 10:40:26 +00:00
|
|
|
$permission = Permission::find($id);
|
|
|
|
|
|
|
|
return Response::detect("permissions.edit", [
|
|
|
|
"permission" => $permission
|
|
|
|
]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2020-06-25 09:19:51 +00:00
|
|
|
* @param Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return void
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
2020-06-25 10:40:26 +00:00
|
|
|
$data = $request->validate([
|
|
|
|
"time" => "required"
|
|
|
|
]);
|
|
|
|
|
|
|
|
$permission = Permission::find($id);
|
|
|
|
|
|
|
|
$permission->update($data);
|
|
|
|
|
|
|
|
$permission->save();
|
|
|
|
|
|
|
|
return Response::detect("permissions.edit", [
|
|
|
|
"permission" => $permission
|
|
|
|
]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2020-06-25 09:19:51 +00:00
|
|
|
* @param int $id
|
|
|
|
* @return void
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
2020-06-25 10:40:26 +00:00
|
|
|
$permission = Permission::find($id);
|
|
|
|
$permission->delete();
|
|
|
|
|
|
|
|
return Response::detect("permissions.destroy");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
}
|