注册

/app/Http/Controller/Auth/RegisterController.php

<?php

namespace App\Http\Controllers\Auth;

use App\Models\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers; class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/ use RegistersUsers; /**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/'; /**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
} /**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
//'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:100', 'unique:users'],
// 'password' => ['required', 'string', 'min:8', 'confirmed'],
'password' => ['required', 'string', 'min:8'],
]);
} /**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
} protected function registered(Request $request) {
return $request->ajax()
? response()->json('success') : redirect($this->redirectPath());
}
}

其中

use App\Models\User; 需要修改为自己的模型

use Illuminate\Http\Request; 添加

protected $redirectTo = '/'; 修改为注册成功后跳转的URL

return Validator::make 根据自己的字段进行修改

在最后添加

protected function registered(Request $request) {
return $request->ajax()
? response()->json('success') : redirect($this->redirectPath());
}

登录

/app/Http/Controller/Auth/LoginController.php

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request; 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 = '/'; /**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
} protected function authenticated(Request $request) {
return $request->ajax()
? response()->json('success') : redirect($this->redirectPath());
}
}

其中

use Illuminate\Http\Request; 添加

在底部添加

    protected function authenticated(Request $request) {
return $request->ajax()
? response()->json('success') : redirect($this->redirectPath());
}

  

laravel5.8ajax请求auth认证返回302的解决方法。的更多相关文章

  1. ajax跨域POST时执行OPTIONS请求服务端返回403forbidden的解决方法

    ajax访问服务端restful api时,由于contentType类型的原因,浏览器会先发送OPTIONS请求. 本人服务端用的是spring mvc框架,web服务器用的是tomcat的,以下给 ...

  2. [datatable]关于在DataTable中执行DataTable.Select("条件")返回DataTable的解决方法

    -- :09关于在DataTable中执行DataTable.Select("条件")返回DataTable的解决方法 在实际编程工程中,常常遇到这样的情况:DataTable并不 ...

  3. Scrapy爬虫返回302重定向问题解决方法

    scrapy爬虫遇到爬取页面时302重定向导致response页面与实际需要爬取的页面信息不一致,导致无法正常获取信息,查看日志存在 scrapy.downloadermiddlewares.redi ...

  4. EasyDarwin返回401 Unauthorized解决方法

    在向EsayDarwin发起 RTSP DESCRIBE请求或者ANNOUNCE推送时,EasyDarwin会返回401 Unauthorized: 原因:在EasyDarwin的RTSP Sessi ...

  5. php unserialize 返回false的解决方法

    php 提供serialize(序列化) 与unserialize(反序列化)方法. 使用serialize序列化后,再使用unserialize反序列化就可以获取原来的数据.(改表结构或者进行下面操 ...

  6. Type.GetType()在跨程序集反射时返回null的解决方法

    在开发中,经常会遇到这种情况,在程序集A.dll中需要反射程序集B.dll中的类型.如果使用稍有不慎,就会产生运行时错误.例如使用Type.GetType("BNameSpace.Class ...

  7. 锐捷认证的一些问题&解决方法

    scau锐捷校园网各种无法吐槽,认证有时候自己掉线了麻痹都打到boss了给我掉线,收费也坑爹,连铁通都比不上. 1.锐捷认证客户端已停止工作: 貌似是毒霸的问题,把金山毒霸关掉再试 2.获取ip地址信 ...

  8. ci中 chrome对favicon.ico请求,导致log报错 解决方法

    chrome浏览器会自动对favicon.ico进行请求,所以当没有为网站添加 favicon.ico 时会出现404的页面错误在实际开发过程中,CI框架 打开 ERROR log,会一直显示ERRO ...

  9. .net 超长URL请求返回404错误-解决方法

    <system.webServer> <security> <requestFiltering> <requestLimits maxQueryString= ...

随机推荐

  1. jmap错误:unknown CollectedHeap type : class sun.jvm.hotspot.gc_interface.CollectedHeap

    原文:https://www.jianshu.com/p/0e5d8db8ed5e 错误场景 今天使用jmap -heap命令查看堆的详细信息报错. [root@instance-2gak1pfv d ...

  2. pandas的行列显示不全的解决方法

    pd.set_option('display.max_rows', 100) # 显示的最大行数(避免只显示部分行数据) pd.set_option('display.max_columns', 10 ...

  3. 前端模板引擎artTemplate.js

    . 关于artTemplate模板引擎的详细原理请移步高性能JavaScript模板引擎原理解析,本文只探讨如何使用.初学前端的人一般对于绑定数据都是使用原生js或者jquery来拼接字符串,此为ha ...

  4. Android Studio在代码重构中的妙用

    代码重构几乎是每个程序员在软件开发中必须要不断去做的事情,以此来不断提高代码的质量.Android Stido(以下简称AS)以其强大的功能,成为当下Android开发工程师最受欢迎的开发工具,也是A ...

  5. li的inline-block出现间隙原因,解决方案

    <style type="text/css"> body{ margin:0 0; padding:0 0; font-size: 14; text-decoratio ...

  6. 19、Python标准库: 日期和时间

    一.time时间模块 import time 1 .时间戳   时间戳(timestamp):时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量. time_stamp = tim ...

  7. 论文编写工具使用(1)latex软件

    1什么是LaTeX 能用编写程序的模式写论文,将你从格式编辑解脱出来,套用现成的论文程序模板,直接生成.LaTEX(/ˈlɑːtɛx/,常被读作/ˈlɑːtɛk/或/ˈleɪtɛk/),文字形式写作L ...

  8. [iOS] 利用 NSAttributedString 进行富文本处理

    /iOS /[iOS] 利用 NSAttributedString 进行富文本处理 2016年4月4日 刘小龙 iOS 许多时候我们需要以各种灵活的形式展现文本信息,即富文本.普通的 text 属性显 ...

  9. LeetCode 722. Remove Comments

    原题链接在这里:https://leetcode.com/problems/remove-comments/ 题目: Given a C++ program, remove comments from ...

  10. kuma kong 团队开发的可视化&&安全的service mesh

    最近service mesh 的开源产品是越来越多了,好多团队都开源了自己的解决方案 maesh 最近kong 团队也开源了自己的service meshkuma 一张参考图 说明 kuma 没有基于 ...