【发布时间】:2018-09-08 04:20:14
【问题描述】:
我使用 laravel 5.4 作为我的应用程序的后端,而我使用 angular 的前端。我正在使用 laravel auth 进行身份验证。
问题是Auth::attempt() 工作正常,如果我立即打印Auth::user(),那么它会打印数据,但如果我尝试在下一个方法中获取它,它会返回false。但此功能在托管服务器中运行良好。
经过测试,
- 将会话从文件更改为数据库。
- kernel.php 中的更改($middleware 的内容)。
- php artisan make:auth 又做了一次吗?
- 用户表列发生变化。
- 将私有 $primarykey = 'id' 添加到模型。
- 向所有路由添加“网络”中间件。
这是我的控制器
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\User;
public function login()
{
if (Auth::attempt(['email' => $email, 'password' => $password ]))
{
$response = array('response' =>'Succssfully Login!' , 'success' => true);
return $response;
}
}
这是我在同一个控制器中使用Auth::check() 的地方
public function check()
{
if(Auth::check())
$response = array('response' =>'Authenticated' , 'success'=>true);
else
$response = array('response' =>'UnAuthenticated' , 'success'=>false);
return $response;
}
我很困惑,因为相同的代码在托管服务器中运行良好,但在 localhost 上运行不正常。为此我需要在 laravel 中做任何与 http 相关的更改吗?
【问题讨论】:
-
您是在使用刀片模板还是在完全不同的服务器上加载您的角度 index.html / p.s。是不是从 laravel 加载的角度应用程序