Answer the question
In order to leave comments, you need to log in
Ajax Login and Registration LARAVEL 5.5 how to do?
I want to implement Login and registration LARAVEL 5.5, on ajax. how can i do? on LoginController I can’t get the data on the Request in any way, just empty, or what other optimal options are there?
Thank you
Answer the question
In order to leave comments, you need to log in
JS
$('#login-form').on('submit', function(e){
e.preventDefault();
$.ajax({
url: $(this).attr('action'),
data: {"username":'asdasdasd',"password":'564a6sd'},
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: 'POST',
dataType: 'JSON',
success: function (html) {
console.log(html);
}
});
console.log('Submit');
});
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Validator;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
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');
}
public function username()
{
return 'username';
}
public function authenticated(Request $request)
{
//
return $request->all();
}
}
Error in Routes. You need to call the login method and not authenticated
Laravel will redirect on successful login to authenticated. Here is how this fragment is arranged in the protected function handleUserWasAuthenticated
if (method_exists($this, 'authenticated')) {
return $this ->authenticated($request, Auth::user());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question