Virajsinh

Laravel Web Route

Sep 23rd, 2025 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | Source Code | 0 0
  1. <?php
  2.  
  3. Route::middleware(['auth'])->name('backend.')->prefix('admin')->group(function () {
  4.    
  5.     Route::get('/dashboard', [AdminController::class, 'dashboard']);
  6.  
  7.     Route::controller(UserController::class)->group(function () {
  8.         Route::get('/users', 'index');
  9.         Route::get('/users/{id}', 'show');
  10.     });
  11.  
  12.     Route::resource('posts', [PostController::class, 'index']);
  13. });
  14.  
  15. // User Routes
  16. // App\Http\Controllers\User\ProfileController
  17. // namespace use for get controller from folder
  18. Route::namespace('User')->group(function () {
  19.     Route::get('/user/profile', [ProfileController::class, 'show']);
  20.     Route::get('/user/settings', [SettingsController::class, 'edit']);
  21. });
  22.  
  23. // missing user then redirect to another page handle
  24. Route::get('/users/{user}', [UsersController::class, 'show'])->missing(function (Request $request) {
  25.     return Redirect::route('users.index');
  26. });
  27.  
  28. // Allows soft-deleted posts to be retrieved
  29. Route::get('/posts/{post}', function (Post $post) {
  30.     return $post;
  31. })->withTrashed();
  32.  
  33. Route::middleware(['role:' . User::ROLE_SUPER_ADMIN])->group(function () {
  34.     // Company
  35.     Route::get('company/list/select2', [App\Http\Controllers\Backend\CompanyController::class, 'select2'])->name('company.select2');
  36.     Route::resource('company', App\Http\Controllers\Backend\CompanyController::class);
  37. });
Advertisement
Add Comment
Please, Sign In to add comment