php - Laravel 7 Auth not working on hosted site
Get the solution ↓↓↓So I am trying to deploy a Laravel site to bluehost however after successful login which should redirect to '/home' and stop. It instead tries to redirect to '/home' then redirects to '/login'. the same code running on localhost with the same database works fine. Other database operations work fine.
Basically the default auth middleware seems to broken somehow.
I used laravel's built in auth to make make the authentication. here is the live site:
LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
web.php
<?php
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
Route::get('/', 'WelcomeController@index')->name('welcome');
Auth::routes();
// Home
Route::get('/home', 'HomeController@index')->name('home');
//Listings
Route::get('/listings/search', 'ListingController@search')->name('search-listings');
Route::get('/listings/delete/{listing}', 'ListingController@destroy')->name('listing-delete');
Route::resource('listings', 'ListingController');
Route::group(['prefix' => 'messages'], function () {
Route::get('/', ['as' => 'messages', 'uses' => 'MessageController@index']);
Route::get('create', ['as' => 'messages.create', 'uses' => 'MessageController@create']);
Route::post('/', ['as' => 'messages.store', 'uses' => 'MessageController@store']);
Route::get('{id}', ['as' => 'messages.show', 'uses' => 'MessageController@show']);
Route::put('/', ['as' => 'messages.update', 'uses' => 'MessageController@update']);
Route::delete('/', ['as' => 'messages.action', 'uses' => 'MessageController@action']);
});
Answer
Solution:
So it turns out there was a new line before <?php in one of my files in app/config !!
Almost drove me crazy. Worked fine on localhost but not on server. If you encounter this issue, check your .php files for new lines at the beginning of the file.
Answer
Solution:
For me, deleting the files in /bootstrap/cache folder except the .gitignore
then running the commandcomposer dumpautoload
worked
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: to enable extensions, verify that they are enabled in your .ini files
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.