Commit 65338fbd authored by Vipul Basapati's avatar Vipul Basapati

Menu Module Responsable Actions complete

parent a5a0e4cd
......@@ -2,27 +2,59 @@
namespace App\Http\Controllers\Backend\Menu;
use App\Models\Menu\Menu;
use Bvipul\Generator\Module;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use App\Http\Responses\ViewResponse;
use App\Http\Responses\RedirectResponse;
use App\Http\Responses\Backend\Menu\EditResponse;
use App\Repositories\Backend\Menu\MenuRepository;
use App\Http\Requests\Backend\Menu\EditMenuRequest;
use App\Http\Responses\Backend\Menu\CreateResponse;
use App\Http\Requests\Backend\Menu\StoreMenuRequest;
use App\Http\Requests\Backend\Menu\CreateMenuRequest;
use App\Http\Requests\Backend\Menu\DeleteMenuRequest;
use App\Http\Requests\Backend\Menu\EditMenuRequest;
use App\Http\Requests\Backend\Menu\ManageMenuRequest;
use App\Http\Requests\Backend\Menu\StoreMenuRequest;
use App\Http\Requests\Backend\Menu\UpdateMenuRequest;
use App\Models\Menu\Menu;
use App\Repositories\Backend\Menu\MenuRepository;
use Illuminate\Support\Facades\DB;
class MenuController extends Controller
{
/**
* Menu Model Object
*
* @var \App\Models\Menu\Menu
*/
protected $menu;
/**
* Module Model Object
*
* @var \Bvipul\Generator\Module
*/
protected $modules;
/**
* Menu Types
*
* @var Array
*/
protected $types;
/**
* @param \App\Repositories\Backend\Menu\MenuRepository $menu
*/
public function __construct(MenuRepository $menu)
public function __construct(MenuRepository $menu, Module $module)
{
$this->menu = $menu;
$this->modules = $module;
$this->types = [
'backend' => 'Backend',
'frontend' => 'Frontend',
];
}
/**
......@@ -30,11 +62,11 @@ class MenuController extends Controller
*
* @param \App\Http\Requests\Backend\Menu\ManageMenuRequest $request
*
* @return \Illuminate\Http\Response
* @return \App\Http\Responses\ViewResponse
*/
public function index(ManageMenuRequest $request)
{
return view('backend.menus.index');
return new ViewResponse('backend.menus.index');
}
/**
......@@ -42,17 +74,11 @@ class MenuController extends Controller
*
* @param \App\Http\Requests\Backend\Menu\CreateMenuRequest $request
*
* @return \Illuminate\Http\Response
* @return \App\Http\Responses\Backend\Menu\CreateResponse
*/
public function create(CreateMenuRequest $request)
{
$types = [
'backend' => 'Backend',
'frontend' => 'Frontend',
];
$modules = DB::table('modules')->get();
return view('backend.menus.create')->withTypes($types)->withModules($modules);
return new CreateResponse($this->types, $this->modules);
}
/**
......@@ -60,13 +86,13 @@ class MenuController extends Controller
*
* @param \App\Http\Requests\Backend\Menu\StoreMenuRequest $request
*
* @return \Illuminate\Http\Response
* @return \App\Http\Responses\RedirectResponse
*/
public function store(StoreMenuRequest $request)
{
$this->menu->create($request->except('_token'));
return redirect()->route('admin.menus.index')->withFlashSuccess(trans('alerts.backend.menus.created'));
return new RedirectResponse('admin.menus.index', ['flash_success' => trans('alerts.backend.menus.created')]);
}
/**
......@@ -75,21 +101,11 @@ class MenuController extends Controller
* @param \App\Models\Menu\Menu $menu
* @param \App\Http\Requests\Backend\Menu\EditMenuRequest $request
*
* @return \Illuminate\Http\Response
* @return \App\Http\Responses\Backend\Menu\EditResponse
*/
public function edit(Menu $menu, EditMenuRequest $request)
{
$types = [
'backend' => 'Backend',
'frontend' => 'Frontend',
];
$modules = DB::table('modules')->get();
return view('backend.menus.edit')
->with('types', $types)
->with('menu', $menu)
->with('modules', $modules);
return new EditResponse($menu, $this->types, $this->modules);
}
/**
......@@ -98,15 +114,13 @@ class MenuController extends Controller
* @param \App\Models\Menu\Menu $menu
* @param \App\Http\Requests\Backend\Menu\UpdateMenuRequest $request
*
* @return \Illuminate\Http\Response
* @return \App\Http\Responses\RedirectResponse
*/
public function update(Menu $menu, UpdateMenuRequest $request)
{
$this->menu->update($menu, $request->all());
return redirect()
->route('admin.menus.index')
->with('flash_success', trans('alerts.backend.menus.updated'));
return new RedirectResponse('admin.menus.index', ['flash_success' => trans('alerts.backend.menus.updated')]);
}
/**
......@@ -115,14 +129,12 @@ class MenuController extends Controller
* @param \App\Models\Menu\Menu $menu
* @param \App\Http\Requests\Backend\Menu\DeleteMenuRequest $request
*
* @return \Illuminate\Http\Response
* @return \App\Http\Responses\RedirectResponse
*/
public function destroy(Menu $menu, DeleteMenuRequest $request)
{
$this->menu->delete($menu);
return redirect()
->route('admin.menus.index')
->with('flash_success', trans('alerts.backend.menus.deleted'));
return new RedirectResponse('admin.menus.index', ['flash_success' => trans('alerts.backend.menus.deleted')]);
}
}
<?php
namespace App\Http\Responses\Backend\Menu;
use Illuminate\Contracts\Support\Responsable;
class CreateResponse implements Responsable
{
/**
* @var Array
*/
protected $types;
/**
* @var \Bvipul\Generator\Module
*/
protected $modules;
/**
* @param Array $types
* @param \Bvipul\Generator\Module $modules
*/
public function __construct($types, $modules)
{
$this->types = $types;
$this->modules = $modules;
}
/**
* In Response.
*
* @param \App\Http\Requests\Request $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function toResponse($request)
{
return view('backend.menus.create')
->withTypes($this->types)
->withModules($this->modules->all());
}
}
<?php
namespace App\Http\Responses\Backend\Menu;
use Illuminate\Contracts\Support\Responsable;
class EditResponse implements Responsable
{
/**
* @var Array
*/
protected $types;
/**
* @var \Bvipul\Generator\Module
*/
protected $modules;
/**
* @var \App\Models\Menu\Menu
*/
protected $menu;
/**
* @param \App\Models\Menu\Menu $menu
* @param Array $types
* @param \Bvipul\Generator\Module $modules
*/
public function __construct($menu, $types, $modules)
{
$this->menu = $menu;
$this->types = $types;
$this->modules = $modules;
}
/**
* toReponse
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function toResponse($request)
{
return view('backend.menus.edit')
->with('types', $this->types)
->with('menu', $this->menu)
->with('modules', $this->modules->all());
}
}
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