I am using version 5.6 of Laravel.
I try to manually write a login controller which on success leads to the dashboard and on fail back to the login.
The problem is when i try to login the MainController allways redirects back to the login. So i checked if the user got logged in properly in the LoginController by checking if Auth::check works afer logging in and found out that it fails which makes it seem like for some reason the user doesn't get logged in properly even though i don't get any error messages.
I searched for hours and tried many things to fix this issue but with no success. So i hope someone can give me a pointer to how to solve this problem.
My setup looks like this:
web.php
<?php
Route::get('/', 'MainController')->name('dashboard');
Route::get('/login', 'LoginController')->name('login');
Route::post('/login/authenticate', 'LoginController@authenticate')->name('authenticate');
MainController.php
<?php
namespace App\Http\Controllers;
use App\User;
use App\Http\Controllers\Controller;
class MainController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function __invoke()
{
return view('maintenance');
}
}
LoginController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\User;
class LoginController extends Controller
{
$user = User::where('userid', $request->input('username'))
->where('user_pass', $request->input('password'))
->where('state', 0)
->first();
if($user) {
Auth::login($user);
if (Auth::check()) {
dd('Auth::check() failed');
}
//return redirect()->route('dashboard');
} else {
return redirect()->back()->withInput();
}
}
}
User.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
protected $primaryKey = 'account_id';
protected $table = 'login';
public $timestamps = false;
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2mO5O1A
via IFTTT
Aucun commentaire:
Enregistrer un commentaire