2017-09-14 22:21:00 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api\Auth;
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Abstracts\Http\ApiController;
|
2017-09-14 22:21:00 +03:00
|
|
|
use App\Http\Requests\Auth\Permission as Request;
|
|
|
|
use App\Models\Auth\Permission;
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Jobs\Auth\CreatePermission;
|
|
|
|
use App\Jobs\Auth\DeletePermission;
|
|
|
|
use App\Jobs\Auth\UpdatePermission;
|
2017-10-16 21:02:32 +03:00
|
|
|
use App\Transformers\Auth\Permission as Transformer;
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
class Permissions extends ApiController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Dingo\Api\Http\Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$permissions = Permission::collect();
|
|
|
|
|
|
|
|
return $this->response->paginator($permissions, new Transformer());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param Permission $permission
|
|
|
|
* @return \Dingo\Api\Http\Response
|
|
|
|
*/
|
|
|
|
public function show(Permission $permission)
|
|
|
|
{
|
|
|
|
return $this->response->item($permission, new Transformer());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param $request
|
|
|
|
* @return \Dingo\Api\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2019-11-16 10:21:14 +03:00
|
|
|
$permission = $this->dispatch(new CreatePermission($request));
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2020-08-11 16:52:10 +03:00
|
|
|
return $this->response->created(route('api.permissions.show', $permission->id));
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param $permission
|
|
|
|
* @param $request
|
|
|
|
* @return \Dingo\Api\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Permission $permission, Request $request)
|
|
|
|
{
|
2019-11-16 10:21:14 +03:00
|
|
|
$permission = $this->dispatch(new UpdatePermission($permission, $request));
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
return $this->item($permission->fresh(), new Transformer());
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param Permission $permission
|
|
|
|
* @return \Dingo\Api\Http\Response
|
|
|
|
*/
|
|
|
|
public function destroy(Permission $permission)
|
|
|
|
{
|
2019-11-16 10:21:14 +03:00
|
|
|
try {
|
|
|
|
$this->dispatch(new DeletePermission($permission));
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
return $this->response->noContent();
|
|
|
|
} catch(\Exception $e) {
|
|
|
|
$this->response->errorUnauthorized($e->getMessage());
|
|
|
|
}
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
}
|