Commit a5a0e4cd authored by Vipul Basapati's avatar Vipul Basapati

Permission Module Responses complete

parent 374d9bd1
...@@ -3,14 +3,18 @@ ...@@ -3,14 +3,18 @@
namespace App\Http\Controllers\Backend\Access\Permission; namespace App\Http\Controllers\Backend\Access\Permission;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Responses\ViewResponse;
use App\Http\Responses\RedirectResponse;
use App\Models\Access\Permission\Permission;
use App\Http\Responses\Backend\Access\Permission\EditResponse;
use App\Http\Responses\Backend\Access\Permission\CreateResponse;
use App\Repositories\Backend\Access\Permission\PermissionRepository;
use App\Http\Requests\Backend\Access\Permission\EditPermissionRequest;
use App\Http\Requests\Backend\Access\Permission\StorePermissionRequest;
use App\Http\Requests\Backend\Access\Permission\CreatePermissionRequest; use App\Http\Requests\Backend\Access\Permission\CreatePermissionRequest;
use App\Http\Requests\Backend\Access\Permission\DeletePermissionRequest; use App\Http\Requests\Backend\Access\Permission\DeletePermissionRequest;
use App\Http\Requests\Backend\Access\Permission\EditPermissionRequest;
use App\Http\Requests\Backend\Access\Permission\ManagePermissionRequest; use App\Http\Requests\Backend\Access\Permission\ManagePermissionRequest;
use App\Http\Requests\Backend\Access\Permission\StorePermissionRequest;
use App\Http\Requests\Backend\Access\Permission\UpdatePermissionRequest; use App\Http\Requests\Backend\Access\Permission\UpdatePermissionRequest;
use App\Models\Access\Permission\Permission;
use App\Repositories\Backend\Access\Permission\PermissionRepository;
/** /**
* Class PermissionController. * Class PermissionController.
...@@ -33,71 +37,69 @@ class PermissionController extends Controller ...@@ -33,71 +37,69 @@ class PermissionController extends Controller
/** /**
* @param ManagePermissionRequest $request * @param ManagePermissionRequest $request
* *
* @return mixed * @return \App\Http\Responses\ViewResponse
*/ */
public function index(ManagePermissionRequest $request) public function index(ManagePermissionRequest $request)
{ {
return view('backend.access.permissions.index'); return new ViewResponse('backend.access.permissions.index');
} }
/** /**
* @param CreatePermissionRequest $request * @param CreatePermissionRequest $request
* *
* @return mixed * @return \App\Http\Responses\Backend\Access\Permission\CreateResponse
*/ */
public function create(CreatePermissionRequest $request) public function create(CreatePermissionRequest $request)
{ {
return view('backend.access.permissions.create') return new CreateResponse($this->permissions);
->withPermissionCount($this->permissions->getCount());
} }
/** /**
* @param StorePermissionRequest $request * @param StorePermissionRequest $request
* *
* @return mixed * @return \App\Http\Responses\RedirectResponse
*/ */
public function store(StorePermissionRequest $request) public function store(StorePermissionRequest $request)
{ {
$this->permissions->create($request->all()); $this->permissions->create($request->all());
return redirect()->route('admin.access.permission.index')->withFlashSuccess(trans('alerts.backend.permissions.created')); return new RedirectResponse('admin.access.permission.index', ['flash_success' => trans('alerts.backend.permissions.created')]);
} }
/** /**
* @param Permission $permission * @param Permission $permission
* @param EditPermissionRequest $request * @param EditPermissionRequest $request
* *
* @return mixed * @return \App\Http\Responses\Backend\Access\Permission\EditResponse
*/ */
public function edit(Permission $permission, EditPermissionRequest $request) public function edit(Permission $permission, EditPermissionRequest $request)
{ {
return view('backend.access.permissions.edit') return new EditResponse($permission);
->withPermission($permission);
} }
/** /**
* @param Permission $permission * @param Permission $permission
* @param UpdatePermissionRequest $request * @param UpdatePermissionRequest $request
* *
* @return mixed * @return \App\Http\Responses\RedirectResponse
*/ */
public function update(Permission $permission, UpdatePermissionRequest $request) public function update(Permission $permission, UpdatePermissionRequest $request)
{ {
$this->permissions->update($permission, $request->all()); $this->permissions->update($permission, $request->all());
return redirect()->route('admin.access.permission.index')->withFlashSuccess(trans('alerts.backend.permissions.updated')); return new RedirectResponse('admin.access.permission.index', ['flash_success' => trans('alerts.backend.permissions.updated')]);
} }
/** /**
* @param Permission $permission * @param Permission $permission
* @param DeletePermissionRequest $request * @param DeletePermissionRequest $request
* *
* @return mixed * @return \App\Http\Responses\RedirectResponse
*/ */
public function destroy(Permission $permission, DeletePermissionRequest $request) public function destroy(Permission $permission, DeletePermissionRequest $request)
{ {
$this->permissions->delete($permission); $this->permissions->delete($permission);
return redirect()->route('admin.access.permission.index')->withFlashSuccess(trans('alerts.backend.permissions.deleted')); return new RedirectResponse('admin.access.permission.index', ['flash_success' => trans('alerts.backend.permissions.deleted')]);
} }
} }
<?php <?php
namespace App\Http\Responses\Backend\Access\User; namespace App\Http\Responses\Backend\Access\Permission;
use Illuminate\Contracts\Support\Responsable; use Illuminate\Contracts\Support\Responsable;
class ShowResponse implements Responsable class CreateResponse implements Responsable
{ {
/** /**
* @var \App\Models\Access\User\User * @var \App\Repositories\Backend\Access\Permission\PermissionRepository
*/ */
protected $user; protected $permissions;
/** /**
* @param \App\Models\Access\User\User $user * @param \App\Repositories\Backend\Access\Permission\PermissionRepository $permissions
*/ */
public function __construct($user) public function __construct($permissions)
{ {
$this->user = $user; $this->permissions = $permissions;
} }
/** /**
...@@ -28,6 +28,7 @@ class ShowResponse implements Responsable ...@@ -28,6 +28,7 @@ class ShowResponse implements Responsable
*/ */
public function toResponse($request) public function toResponse($request)
{ {
return view('backend.access.users.show')->withUser($this->user); return view('backend.access.permissions.create')
->withPermissionCount($this->permissions->getCount());
} }
} }
<?php
namespace App\Http\Responses\Backend\Access\Permission;
use Illuminate\Contracts\Support\Responsable;
class EditResponse implements Responsable
{
/**
* @var \App\Models\Access\Permission\Permission
*/
protected $permission;
/**
* @param \App\Models\Access\Permission\Permission $permission
*/
public function __construct($permission)
{
$this->permission = $permission;
}
/**
* toReponse
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function toResponse($request)
{
return view('backend.access.permissions.edit')
->withPermission($this->permission);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment