Commit 9a2295da authored by Nicolas Widart's avatar Nicolas Widart

Create a menu item

parent 838c1ec7
<?php namespace Modules\Menu\Http\Controllers\Admin;
use Illuminate\Routing\Redirector;
use Laracasts\Flash\Flash;
use Modules\Menu\Entities\Menu;
use Modules\Menu\Http\Requests\CreateMenuItemRequest;
use Modules\Menu\Repositories\MenuItemRepository;
class MenuItemController
{
/**
* @var MenuItemRepository
*/
private $menuItem;
/**
* @var Redirector
*/
private $redirector;
public function __construct(MenuItemRepository $menuItem, Redirector $redirector)
{
$this->menuItem = $menuItem;
$this->redirector = $redirector;
}
public function create(Menu $menu)
{
return view('menu::admin.menuitems.create', compact('menu'));
......@@ -12,7 +30,10 @@ class MenuItemController
public function store(Menu $menu, CreateMenuItemRequest $request)
{
dd('Form posted', $menu, $request->all());
$this->menuItem->create(array_merge($request->all(), ['menu_id' => $menu->id]));
Flash::success('Menu item created!');
return $this->redirector->route('dashboard.menu.edit', [$menu->id]);
}
public function update(Menu $menu)
......
<?php namespace Modules\Menu\Repositories\Eloquent;
use Modules\Core\Internationalisation\Helper;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Menu\Entities\Menuitem;
use Modules\Menu\Repositories\MenuItemRepository;
......@@ -8,12 +9,11 @@ class EloquentMenuItemRepository extends EloquentBaseRepository implements MenuI
{
public function create($data)
{
dd($data);
$menuItem = new Menuitem;
$menuItem->menu_id = $data['menu_id'];
$menuItem->page_id = $data['page_id'];
$menuItem->target = $data['target'];
$menuItem->module_name = $data['module_name'];
$menuItem->module_name = $data['module'];
unset($data['menu_id'], $data['page_id'], $data['target'], $data['module_name']);
......
<div class="form-group">
<label for="page">{{ trans('menu::menu-items.form.page') }}</label>
<select class="form-control" name="page" id="page">
<select class="form-control" name="page_id" id="page">
<option value=""></option>
</select>
</div>
......
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