yu0307
952
25
Laravel

[Package Development] Why is Post Route in a Package thrown an exception without a message?

Posted 1 year ago by yu0307

So here is what I was trying to do. In a nutshell, I'm trying to authenticate in a package. So I have:

Route::group(['middleware' => ['web']], function(){
    Route::get('/login', 'Vendor\controller\[email protected]')->name('login');
}

Route::post('/login', 'Vendor\controller\[email protected]');

Route::group(['middleware' => 'auth'], function () {
    Route::get('/','Vendor\controller\[email protected]')->name('Home');
}

I found out that If I go with the setup above. you can successfully authenticate under [email protected], but the session data will not persist which means if I redirect to another page it will ask me to login again. Because route POST /login is not using middleware web. But if I put the POST route into the web middleware group, like this:

Route::group(['middleware' => ['web']], function(){
    Route::get('/login', 'Vendor\controller\[email protected]')->name('login');
    Route::post('/login', 'Vendor\controller\[email protected]');   
}

it gives me an exception without any message.

"message": "",
    "exception": "Symfony\Component\HttpKernel\Exception\HttpException",
    "file": "/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php",
    "line": 203,

Please notice this is in a package, so the route file is NOT the one in /routes/web.php

Please help~~~~~~~~~

Please sign in or create an account to participate in this conversation.