Commit e40dde27 by Aan Choesni Herlingga

bug fix create menu from page

parent c0d0728e
......@@ -7,7 +7,6 @@ use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Webprofile\Menu;
use Validator;
use Uuid;
use Alert;
use App\Repositories\Webprofile\En\MenuRepository;
use Crypt;
......@@ -32,9 +31,9 @@ class MenuController extends Controller
public function index()
{
$parent = Menu::where('status', '1')->whereNull('url')->whereIn('level', [1, 2])->pluck('name', 'id');
$page = Pages::where('post_status', '1')->pluck('title', 'id');
$page = Pages::orderBy('title', 'asc')->pluck('title', 'id');
$data = Menu::with(['rEn'])->select('id', 'parent', 'name', 'url', 'level', 'urutan')->orderby('level', 'asc')->orderby('urutan', 'asc')->get();
$arr = $this->build_menu();
return view('webprofile.backend.menu.index', compact('parent', 'page', 'data', 'arr'))->withTitle('Menu');
......@@ -56,9 +55,9 @@ class MenuController extends Controller
if ($this->menu_has_child($item->parent)) {
$menu[$i]['child'] = $this->menu_get_child($item->id);
}
$i++;
++$i;
}
return $menu;
}
......@@ -89,7 +88,7 @@ class MenuController extends Controller
if ($this->menu_has_child($citem->parent)) {
$cmenu[$i]['child'] = $this->menu_get_child($citem->id);
}
$i++;
++$i;
}
return $cmenu;
......@@ -99,10 +98,10 @@ class MenuController extends Controller
{
$cur_menu = Menu::where('id', Crypt::decrypt($id))->first();
if ($cur_menu->parentlevel == null) {
$up_menu = Menu::where('level', $cur_menu->level)->where('urutan', (int)$cur_menu->urutan-1)->first();
$up_menu = Menu::where('level', $cur_menu->level)->where('urutan', (int) $cur_menu->urutan - 1)->first();
}
if ($cur_menu->parentlevel != null) {
$up_menu = Menu::where('parent', $cur_menu->parent)->where('level', $cur_menu->level)->where('urutan', (int)$cur_menu->urutan-1)->first();
$up_menu = Menu::where('parent', $cur_menu->parent)->where('level', $cur_menu->level)->where('urutan', (int) $cur_menu->urutan - 1)->first();
}
Menu::where('id', Crypt::decrypt($id))->update([
......@@ -112,7 +111,7 @@ class MenuController extends Controller
]);
Menu::where('id', $up_menu->id)->update([
'urutan' => $up_menu->urutan+1,
'urutan' => $up_menu->urutan + 1,
'userid_created' => Auth::user()->name,
'updated_at' => date('Y-m-d H:i:s'),
]);
......@@ -124,10 +123,10 @@ class MenuController extends Controller
{
$cur_menu = Menu::where('id', Crypt::decrypt($id))->first();
if ($cur_menu->parentlevel == null) {
$up_menu = Menu::where('level', $cur_menu->level)->where('urutan', (int)$cur_menu->urutan+1)->first();
$up_menu = Menu::where('level', $cur_menu->level)->where('urutan', (int) $cur_menu->urutan + 1)->first();
}
if ($cur_menu->parentlevel != null) {
$up_menu = Menu::where('parent', $cur_menu->parent)->where('level', $cur_menu->level)->where('urutan', (int)$cur_menu->urutan+1)->first();
$up_menu = Menu::where('parent', $cur_menu->parent)->where('level', $cur_menu->level)->where('urutan', (int) $cur_menu->urutan + 1)->first();
}
Menu::where('id', Crypt::decrypt($id))->update([
......@@ -137,7 +136,7 @@ class MenuController extends Controller
]);
Menu::where('id', $up_menu->id)->update([
'urutan' => $up_menu->urutan-1,
'urutan' => $up_menu->urutan - 1,
'userid_created' => Auth::user()->name,
'updated_at' => date('Y-m-d H:i:s'),
]);
......@@ -152,13 +151,13 @@ class MenuController extends Controller
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
......@@ -168,6 +167,7 @@ class MenuController extends Controller
if ($validator->fails()) {
$errormessage = $validator->messages();
return redirect()->route('menu.index')
->withErrors($validator)
->withInput();
......@@ -178,7 +178,7 @@ class MenuController extends Controller
} else {
$getlevelparent = Menu::where('id', $request->input('parent'))->first()->level;
$parentlevel = $getlevelparent;
$level = (int)$getlevelparent + 1;
$level = (int) $getlevelparent + 1;
}
$urutan = Menu::where('level', $level)->where('parent', $request->input('parent'))->max('urutan');
......@@ -186,7 +186,7 @@ class MenuController extends Controller
$data['status'] = 1;
$data['level'] = $level;
$data['parentlevel'] = $parentlevel;
$data['urutan'] = $urutan+1;
$data['urutan'] = $urutan + 1;
$data['userid_created'] = Auth::user()->name;
$data['userid_updated'] = Auth::user()->name;
......@@ -196,7 +196,8 @@ class MenuController extends Controller
Alert::success('Data berhasil disimpan')->persistent('Ok');
$successmessage = "Proses Tambah Menu Berhasil !!";
$successmessage = 'Proses Tambah Menu Berhasil !!';
return redirect()->route('menu.index')->with('successMessage', $successmessage);
}
}
......@@ -212,13 +213,14 @@ class MenuController extends Controller
$this->repoEn->store($dataEn);
}
public function newstorepage(Request $request)
public function storepage(Request $request)
{
$data = $request->except('_token');
$validator = Validator::make($data, Menu::$rules, Menu::$errormessage);
if ($validator->fails()) {
$errormessage = $validator->messages();
return redirect()->route('menu.index')
->withErrors($validator)
->withInput();
......@@ -229,7 +231,7 @@ class MenuController extends Controller
} else {
$getlevelparent = Menu::where('id', $request->input('parentpage'))->first()->level;
$parentlevel = $getlevelparent;
$level = (int)$getlevelparent + 1;
$level = (int) $getlevelparent + 1;
}
$urutan = Menu::where('level', $level)->where('parent', $request->input('parentpage'))->max('urutan');
......@@ -239,7 +241,7 @@ class MenuController extends Controller
$data['name'] = $page->title;
$data['level'] = $level;
$data['parentlevel'] = $parentlevel;
$data['urutan'] = $urutan+1;
$data['urutan'] = $urutan + 1;
$data['parent'] = $request->input('parentpage');
$data['url'] = '/page/'.$page->slug;
$data['status'] = 1;
......@@ -252,7 +254,8 @@ class MenuController extends Controller
Alert::success('Data berhasil disimpan')->persistent('Ok');
$successmessage = "Proses Tambah Menu Berhasil !!";
$successmessage = 'Proses Tambah Menu Berhasil !!';
return redirect()->route('menu.index')->with('successMessage', $successmessage);
}
}
......@@ -260,41 +263,42 @@ class MenuController extends Controller
/**
* Display the specified resource.
*
* @param \App\Models\Menu $menu
* @param \App\Models\Menu $menu
*
* @return \Illuminate\Http\Response
*/
public function show(Menu $menu)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Menu $menu
* @param \App\Models\Menu $menu
*
* @return \Illuminate\Http\Response
*/
public function edit(Menu $menu)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Menu $menu
* @param \Illuminate\Http\Request $request
* @param \App\Models\Menu $menu
*
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Menu $menu)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Menu $menu
* @param \App\Models\Menu $menu
*
* @return \Illuminate\Http\Response
*/
public function destroy($id)
......@@ -306,7 +310,7 @@ class MenuController extends Controller
Menu::where('id', Crypt::decrypt($id))->delete(Crypt::decrypt($id));
$tataurut = Menu::where('level', $level)->orderBy('urutan', 'asc')->get();
$urut = 1;
foreach ($tataurut as $value) {
Menu::where('id', $value->id)->update([
'urutan' => $urut++,
......
......@@ -13,7 +13,9 @@ class Menu extends Model
public $incrementing = false;
protected $table = 'swp_menus';
protected $guarded = [];
protected $fillable = [
'id', 'name', 'url', 'mode', 'status', 'parent', 'urutan', 'parentlevel', 'level', 'userid_created', 'userid_updated',
];
public static $rules = [
// 'name' => 'required',
......
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