2.6.1 Resource Menus menu.menu.index (ok)
Last updated
Last updated
C:\xampp82\htdocs\testvn\routes\web.php
<?php
use App\Http\Controllers\BannerController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\MenuController;
use App\Http\Controllers\UsersController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::group(['middleware' => 'get.menu'], function () {
Route::get('/', function () {
return view('dashboard.homepage');
});
Auth::routes();
Route::get('/home', [HomeController::class, 'index'])->name('home');
Route::group(['middleware' => ['role:admin']], function () {
Route::get('/test-role-admin', function () {
echo "Hello Admin";
});
Route::resource('users', UsersController::class)->except(['create', 'store']);
});
Route::group(['prefix' => 'menu/menu','as' => 'menu.menu.'], function () {
Route::resource('/', MenuController::class);
});
});
C:\xampp82\htdocs\testvn\app\Http\Controllers\MenuController.php
<?php
namespace App\Http\Controllers;
use App\Models\Menulist;
use Illuminate\Http\Request;
class MenuController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('menus.index', array(
'menulist' => Menulist::all()
));
}
public function create(Request $request)
{
return view('menus.create');
}
public function edit($id)
{
return view('menus.edit');
}
public function update(Request $request, $id)
{
}
public function destroy($id)
{
}
}
C:\xampp82\htdocs\testvn\resources\views\menus\index.blade.php
@extends('layouts.main')
@section('main')
<div class="container-fluid">
<div class="fade-in">
<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-header">
<h4>Menus list</h4>
</div>
<div class="card-body">
<div class="row mb-3 ml-3">
<a class="btn btn-lg btn-primary" href="{{ route('menu.menu.create') }}">Add new menu</a>
</div>
<table class="table table-striped table-bordered datatable">
<thead>
<tr>
<th>Name</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@foreach($menulist as $menu1)
<tr>
<td>
{{ $menu1->name }}
</td>
<td>
<a class="btn btn-primary" href="{{ route('menu.menu.index' ) }}">Show</a>
</td>
<td>
<a class="btn btn-primary" href="{{ route('menu.menu.edit', $menu1->id ) }}">Edit</a>
</td>
<td>
<a class="btn btn-danger" href="{{ route('menu.menu.destroy', $menu1->id ) }}">Delete</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection