Commit addee78f authored by Vipul Basapati's avatar Vipul Basapati

Page Module Responsable Trait implementation complete

parent 65338fbd
...@@ -2,15 +2,18 @@ ...@@ -2,15 +2,18 @@
namespace App\Http\Controllers\Backend\Pages; namespace App\Http\Controllers\Backend\Pages;
use App\Models\Page\Page;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Responses\ViewResponse;
use App\Http\Responses\RedirectResponse;
use App\Http\Responses\Backend\Page\EditResponse;
use App\Repositories\Backend\Pages\PagesRepository;
use App\Http\Requests\Backend\Pages\EditPageRequest;
use App\Http\Requests\Backend\Pages\StorePageRequest;
use App\Http\Requests\Backend\Pages\CreatePageRequest; use App\Http\Requests\Backend\Pages\CreatePageRequest;
use App\Http\Requests\Backend\Pages\DeletePageRequest; use App\Http\Requests\Backend\Pages\DeletePageRequest;
use App\Http\Requests\Backend\Pages\EditPageRequest;
use App\Http\Requests\Backend\Pages\ManagePageRequest; use App\Http\Requests\Backend\Pages\ManagePageRequest;
use App\Http\Requests\Backend\Pages\StorePageRequest;
use App\Http\Requests\Backend\Pages\UpdatePageRequest; use App\Http\Requests\Backend\Pages\UpdatePageRequest;
use App\Models\Page\Page;
use App\Repositories\Backend\Pages\PagesRepository;
/** /**
* Class PagesController. * Class PagesController.
...@@ -30,70 +33,69 @@ class PagesController extends Controller ...@@ -30,70 +33,69 @@ class PagesController extends Controller
/** /**
* @param \App\Http\Requests\Backend\Pages\ManagePageRequest $request * @param \App\Http\Requests\Backend\Pages\ManagePageRequest $request
* *
* @return mixed * @return \App\Http\Responses\ViewResponse
*/ */
public function index(ManagePageRequest $request) public function index(ManagePageRequest $request)
{ {
return view('backend.pages.index'); return new ViewResponse('backend.pages.index');
} }
/** /**
* @param \App\Http\Requests\Backend\Pages\CreatePageRequest $request * @param \App\Http\Requests\Backend\Pages\CreatePageRequest $request
* *
* @return mixed * @return \App\Http\Responses\ViewResponse
*/ */
public function create(CreatePageRequest $request) public function create(CreatePageRequest $request)
{ {
return view('backend.pages.create'); return new ViewResponse('backend.pages.create');
} }
/** /**
* @param \App\Http\Requests\Backend\Pages\StorePageRequest $request * @param \App\Http\Requests\Backend\Pages\StorePageRequest $request
* *
* @return mixed * @return \App\Http\Responses\RedirectResponse
*/ */
public function store(StorePageRequest $request) public function store(StorePageRequest $request)
{ {
$this->pages->create($request->except(['_token'])); $this->pages->create($request->except(['_token']));
return redirect()->route('admin.pages.index')->withFlashSuccess(trans('alerts.backend.pages.created')); return new RedirectResponse('admin.pages.index', ['flash_success' => trans('alerts.backend.pages.created')]);
} }
/** /**
* @param \App\Models\Page\Page $page * @param \App\Models\Page\Page $page
* @param \App\Http\Requests\Backend\Pages\EditPageRequest $request * @param \App\Http\Requests\Backend\Pages\EditPageRequest $request
* *
* @return mixed * @return \App\Http\Responses\Backend\Page\EditResponse
*/ */
public function edit(Page $page, EditPageRequest $request) public function edit(Page $page, EditPageRequest $request)
{ {
return view('backend.pages.edit') return new EditResponse($page);
->withPage($page);
} }
/** /**
* @param \App\Models\Page\Page $page * @param \App\Models\Page\Page $page
* @param \App\Http\Requests\Backend\Pages\UpdatePageRequest $request * @param \App\Http\Requests\Backend\Pages\UpdatePageRequest $request
* *
* @return mixed * @return \App\Http\Responses\RedirectResponse
*/ */
public function update(Page $page, UpdatePageRequest $request) public function update(Page $page, UpdatePageRequest $request)
{ {
$this->pages->update($page, $request->except(['_method', '_token'])); $this->pages->update($page, $request->except(['_method', '_token']));
return redirect()->route('admin.pages.index')->withFlashSuccess(trans('alerts.backend.pages.updated')); return new RedirectResponse('admin.pages.index', ['flash_success' => trans('alerts.backend.pages.updated')]);
} }
/** /**
* @param \App\Models\Page\Page $page * @param \App\Models\Page\Page $page
* @param \App\Http\Requests\Backend\Pages\DeletePageRequest $request * @param \App\Http\Requests\Backend\Pages\DeletePageRequest $request
* *
* @return mixed * @return \App\Http\Responses\RedirectResponse
*/ */
public function destroy(Page $page, DeletePageRequest $request) public function destroy(Page $page, DeletePageRequest $request)
{ {
$this->pages->delete($page); $this->pages->delete($page);
return redirect()->route('admin.pages.index')->withFlashSuccess(trans('alerts.backend.pages.deleted')); return new RedirectResponse('admin.pages.index', ['flash_success' => trans('alerts.backend.pages.deleted')]);
} }
} }
<?php
namespace App\Http\Responses\Backend\Page;
use Illuminate\Contracts\Support\Responsable;
class CreateResponse implements Responsable
{
/**
* In Response.
*
* @param \App\Http\Requests\Request $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function toResponse($request)
{
//
}
}
<?php
namespace App\Http\Responses\Backend\Page;
use Illuminate\Contracts\Support\Responsable;
class EditResponse implements Responsable
{
/**
* @var \App\Models\Page\Page
*/
protected $page;
/**
* @param \App\Models\Page\Page $page
*/
public function __construct($page)
{
$this->page = $page;
}
/**
* toReponse
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function toResponse($request)
{
return view('backend.pages.edit')
->withPage($this->page);
}
}
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