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\Role as Request;
|
|
|
|
use App\Models\Auth\Role;
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Jobs\Auth\CreateRole;
|
|
|
|
use App\Jobs\Auth\DeleteRole;
|
|
|
|
use App\Jobs\Auth\UpdateRole;
|
2017-10-16 21:02:32 +03:00
|
|
|
use App\Transformers\Auth\Role as Transformer;
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
class Roles extends ApiController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Dingo\Api\Http\Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$roles = Role::with('permissions')->collect();
|
|
|
|
|
|
|
|
return $this->response->paginator($roles, new Transformer());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2017-09-18 16:58:25 +03:00
|
|
|
* @param Role $role
|
2017-09-14 22:21:00 +03:00
|
|
|
* @return \Dingo\Api\Http\Response
|
|
|
|
*/
|
2017-09-18 16:58:25 +03:00
|
|
|
public function show(Role $role)
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
|
|
|
return $this->response->item($role, 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
|
|
|
$role = $this->dispatch(new CreateRole($request));
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
return $this->response->created(url('api/roles/' . $role->id));
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param $role
|
|
|
|
* @param $request
|
|
|
|
* @return \Dingo\Api\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Role $role, Request $request)
|
|
|
|
{
|
2019-11-16 10:21:14 +03:00
|
|
|
$role = $this->dispatch(new UpdateRole($role, $request));
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
return $this->item($role->fresh(), new Transformer());
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param Role $role
|
|
|
|
* @return \Dingo\Api\Http\Response
|
|
|
|
*/
|
|
|
|
public function destroy(Role $role)
|
|
|
|
{
|
2019-11-16 10:21:14 +03:00
|
|
|
try {
|
|
|
|
$this->dispatch(new DeleteRole($role));
|
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
|
|
|
}
|
|
|
|
}
|