Home > Enterprise >  artisan optimize laravel 9
artisan optimize laravel 9

Time:09-01

when i do : php artisan optimize I have this error : there you can see my web.php and my error

My error in terminal when i try optimize :

php artisan optimize

   INFO  Caching the framework bootstrap files.  

  config ........................................................... 52ms DONE
  routes ........................................................... 92ms FAIL

   LogicException 

  Unable to prepare route [logout] for serialization. Another route has already been assigned name [logout].

  at vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteCollection.php:219
    215▕             $route->name($this->generateRouteName());
    216▕ 
    217▕             $this->add($route);
    218▕         } elseif (! is_null($symfonyRoutes->get($name))) {
  ➜ 219▕             throw new LogicException("Unable to prepare route [{$route->uri}] for serialization. Another route has already been assigned name [{$name}].");
    220▕         }
    221▕ 
    222▕         $symfonyRoutes->add($route->getName(), $route->toSymfonyRoute());
    223▕ 

       35 vendor frames 
  36  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()


web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PostController;
use App\Http\Controllers\ConversationController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\SubCategoryController;
use App\Http\Controllers\ThreadController;
use App\Http\Controllers\User\SubCategoryController as UserSubCategoryController;
use App\Http\Controllers\User\ThreadController as UserThreadController;



/*
|--------------------------------------------------------------------------
| 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::get('/', function () {
   return redirect('/home');
});



Route::get("/logout", function () {
   Auth::logout();
   return redirect()->route("login");
})->name("logout");

Auth::routes(['verify' => true]);
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/admin', [App\Http\Controllers\AdminController::class, 'index']);
Route::get('/regles', [App\Http\Controllers\HomeController::class, 'regles'])->name('regles');


Route::resource('posts', PostController::class);


Route::get('createconversationlist/', [ConversationController::class, 'showlist']);
Route::get('createconversation/', [ConversationController::class, 'createwithout']);
Route::get('createconversation/{title}', [ConversationController::class, 'create']);
Route::get('convshow/{id}', [ConversationController::class, 'convshow']);
Route::post('storeconversation', [ConversationController::class, 'store'])->name('conversation.store');
Route::post('replytoconv', [ConversationController::class, 'replytoconv'])->name('conversation.reply');

Route::get('updatesinglestatus/{id}', [ConversationController::class, 'updatestatus']);

//SUPERADMIN
Route::group(['middleware' => ['auth', 'role:ROLE_SUPERADMIN'], 'prefix' => 'superadmin'], function () {

   Route::get('/', [App\Http\Controllers\SuperAdminController::class, 'index'])->name('superadmin');

   //Utilisateur
   Route::resource('user', UserController::class);
   Route::get('users/destroy/{id}', [UserController::class, 'destroy'])->name('user.destroy');



   //Category
   Route::resource('categories', CategoryController::class);
   Route::get('categories/destroy/{id}', [CategoryController::class, 'destroy'])->name('categories.destroy');

   //Sub Category
   Route::resource('subcategories', SubCategoryController::class);
   Route::get('subcategories/destroy/{id}', [SubCategoryController::class, 'destroy'])->name('subcategories.destroy');

   //Thread
   Route::resource('threads', ThreadController::class);
   Route::get('threads/destroy/{id}', [ThreadController::class, 'destroy'])->name('threads.destroy');
   Route::post('threads/block', [ThreadController::class, 'block'])->name('threads.block');
   // Conversation
   Route::resource('conversation', ConversationController::class);
});


//USER
Route::group(['middleware' => ['auth', 'role:ROLE_USER,ROLE_SUPERADMIN']], function () {
   Route::get('subcategory/{subcategory}', [UserSubCategoryController::class, 'subcategory'])->name('subcategory.thread');
   Route::get('subcategory/thread/{subcategory}', [UserThreadController::class, 'create'])->name('thread.create');
   Route::post('subcategory/thread/{subcategory}', [UserThreadController::class, 'store'])->name('thread.store');

   Route::get('thread/{thread}', [UserThreadController::class, 'show'])->name('thread.show');
});

Route::get('profile/change-password', [App\Http\Controllers\HomeController::class, 'changePassword'])->name('change-password');
Route::post('profile/change-password', [App\Http\Controllers\HomeController::class, 'updatePassword'])->name('update-password');
Route::get('/profile', [App\Http\Controllers\HomeController::class, 'profile'])->name('profile');
Route::post('/profile', [App\Http\Controllers\HomeController::class, 'updateSecretword'])->name('update-secretword'); ```


I don't know in which file or code i have error and how can i resolve this, i'm student i try to create project for school and i have this error it's 2 days. Someone can help resolve this?

CodePudding user response:

it means that :

there is another route with same name "logout"

i hope it was useful

CodePudding user response:

I think that Laravel has already assigned that name so you have to change the route name

CodePudding user response:

Change it please as Laravel has by default a route under name "logout".

Route::get("/logout", function () {
       Auth::logout();
       return redirect()->route("login");
    })->name("customLogout");

And change it to another URL:

Route::get('/superadmin-page', [App\Http\Controllers\SuperAdminController::class, 'index'])->name('superadmin');
  • Related