Commit d1398a1f by Aan Choesni Herlingga

bug fix updown menu

parent a749365a
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
namespace App\Http\Controllers\Webprofile\Backend; namespace App\Http\Controllers\Webprofile\Backend;
use App\Models\Webprofile\Pages; use Alert;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Webprofile\Menu; use App\Models\Webprofile\Menu;
use Validator; use App\Models\Webprofile\Pages;
use Alert;
use App\Repositories\Webprofile\En\MenuRepository; use App\Repositories\Webprofile\En\MenuRepository;
use App\Repositories\Webprofile\MenuRepository as WebprofileMenuRepository; use App\Repositories\Webprofile\MenuRepository as WebprofileMenuRepository;
use Crypt;
use Auth; use Auth;
use Crypt;
use Illuminate\Http\Request;
use Statickidz\GoogleTranslate; use Statickidz\GoogleTranslate;
use Validator;
class MenuController extends Controller class MenuController extends Controller
{ {
...@@ -83,16 +83,17 @@ class MenuController extends Controller ...@@ -83,16 +83,17 @@ class MenuController extends Controller
return $cmenu; return $cmenu;
} }
public function menu_up($id) public function menu_up($id, $urut = 1)
{ {
$cur_menu = Menu::where('id', Crypt::decrypt($id))->first(); $cur_menu = Menu::where('id', Crypt::decrypt($id))->first();
if ($cur_menu->parentlevel == null) { 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 - $urut)->first();
} }
if ($cur_menu->parentlevel != null) { 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 - $urut)->first();
} }
if ($up_menu) {
Menu::where('id', Crypt::decrypt($id))->update([ Menu::where('id', Crypt::decrypt($id))->update([
'urutan' => $up_menu->urutan, 'urutan' => $up_menu->urutan,
'userid_created' => Auth::user()->name, 'userid_created' => Auth::user()->name,
...@@ -108,16 +109,20 @@ class MenuController extends Controller ...@@ -108,16 +109,20 @@ class MenuController extends Controller
return redirect()->route('menu.index'); return redirect()->route('menu.index');
} }
public function menu_down($id) return $this->menu_up($id, $urut + 1);
}
public function menu_down($id, $urut = 1)
{ {
$cur_menu = Menu::where('id', Crypt::decrypt($id))->first(); $cur_menu = Menu::where('id', Crypt::decrypt($id))->first();
if ($cur_menu->parentlevel == null) { 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 + $urut)->first();
} }
if ($cur_menu->parentlevel != null) { 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 + $urut)->first();
} }
if ($up_menu) {
Menu::where('id', Crypt::decrypt($id))->update([ Menu::where('id', Crypt::decrypt($id))->update([
'urutan' => $up_menu->urutan, 'urutan' => $up_menu->urutan,
'userid_created' => Auth::user()->name, 'userid_created' => Auth::user()->name,
...@@ -133,6 +138,9 @@ class MenuController extends Controller ...@@ -133,6 +138,9 @@ class MenuController extends Controller
return redirect()->route('menu.index'); return redirect()->route('menu.index');
} }
return $this->menu_down($id, $urut + 1);
}
/** /**
* Show the form for creating a new resource. * Show the form for creating a new resource.
* *
...@@ -145,8 +153,6 @@ class MenuController extends Controller ...@@ -145,8 +153,6 @@ class MenuController extends Controller
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
* *
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function store(Request $request) public function store(Request $request)
...@@ -269,8 +275,6 @@ class MenuController extends Controller ...@@ -269,8 +275,6 @@ class MenuController extends Controller
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
* *
* @param \App\Models\Menu $menu
*
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function edit($id) public function edit($id)
...@@ -290,9 +294,6 @@ class MenuController extends Controller ...@@ -290,9 +294,6 @@ class MenuController extends Controller
/** /**
* Update the specified resource in storage. * Update the specified resource in storage.
* *
* @param \Illuminate\Http\Request $request
* @param \App\Models\Menu $menu
*
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
...@@ -313,8 +314,6 @@ class MenuController extends Controller ...@@ -313,8 +314,6 @@ class MenuController extends Controller
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
* *
* @param \App\Models\Menu $menu
*
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function destroy($id) public function destroy($id)
......
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