0
I created a custom Auth controller in Laravel 5.5 with the "store" action inside it, then I authenticated using the method auth->attempt()
returning true
. So far so good, the problem starts when I try to use the "auth" middleware for my dashboard routes, the authentication middleware always redirects to the login action.
Routes:
Route::group(['middleware' => ['auth', 'web']], function () {
Route::get('/painel/', ['as' => 'painel.dashboard', 'uses' => 'DashboardController@index']);
});
Route::get('/login', ['middleware' => 'web', 'as' => 'login', 'uses' => 'AuthController@index']);
Route::group(['middleware' => ['web']], function () {
Route::get('/painel/auth', ['as' => 'painel.auth.index', 'uses' => 'AuthController@index']);
Route::post('/painel/auth/store', ['as' => 'painel.auth.store', 'uses' => 'AuthController@store']);
});
Controller:
<?php
namespace App\Applications\Painel\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Auth\AuthManager as Auth;
class AuthController extends BaseController
{
/**
* @var Guard
*/
private $auth;
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
public function index()
{
return view('painel::auth.index');
}
public function store(Request $request)
{
$data = $request->only(['email', 'password']);
// This condition always return true, but after Laravel return to action index...
if ($this->auth->attempt($data)) {
return redirect()->route('painel.dashboard');
}
return redirect()->back();
}
}
While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - Of Revision
– hugocsl
@hugocsl Actually this answer is more like ad face.
– Leandro Angelo
@Leandroangelo can even be interpreted as spam even, but as it is within the subject of the tag, and Bruno is a member of STOF for more than 2 years I reviewed as "response per link" same....
– hugocsl
@hugocsl Fact, my failure by contact data and website with resume.
– Leandro Angelo
Good friends, my intention was to really help, and as I work on two projects at the same time, I took a little time to help. Actually my site is a resume, but there are contact data beyond this email, in case you have doubts, since lately I have entered little here in STOF. I hope you understand that I am not trying to promote myself but help, here is a community open to doubts and not Linkedin, I mean, it would not make sense to try to promote myself in this environment. I hope you review your arguments, hugs! @Leandroangelo
– Bruno Henrique Gaignoux Gomes