Задать вопрос
  • Ajax Логин и регистрация LARAVEL 5.5, как сделать?

    ARMbrain
    @ARMbrain Автор вопроса
    Веб-Разработчик
    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');
    });


    Routes
    Route::post('/login', ['uses'=>'Auth\LoginController@authenticated']);


    LoginController.php
    <?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();
        }
    }
    Ответ написан
    Комментировать