日安。我的身份验证出现了问题,我总是将其重新定向到登录页面。当我用下面的代码添加routes/web.php时,我发现
Route::group(['middleware' => 'auth'], function() {
}该页面始终被重定向回登录页面。但是当我删除上面的代码时,我就可以进入主页了。我想知道如何解决这个问题。我在过去的项目中使用了路由组,我对此没有任何问题。
更新:我使用了php artisan测试并重新修改了我的ExampleTest.php代码。
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use App\User;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
public function testApplication()
{
$user = factory(User::class)->create();
$response = $this->actingAs($user)
->withSession(['foo' => 'bar'])
->get('/');
}
}以下是结果
C:\xampp\htdocs\nuadu_helpdesk\vendor\laravel\framework\src\Illuminate\Database\Eloquent\FactoryBuilder.php:273
269| */
270| protected function getRawAttributes(array $attributes = [])
271| {
272| if (! isset($this->definitions[$this->class])) {
> 273| throw new InvalidArgumentException("Unable to locate factory for [{$this->class}].");
274| }
275|
276| $definition = call_user_func(
277| $this->definitions[$this->class],
1 C:\xampp\htdocs\nuadu_helpdesk\vendor\laravel\framework\src\Illuminate\Database\Eloquent\FactoryBuilder.php:296
Illuminate\Database\Eloquent\FactoryBuilder::getRawAttributes([])
2 C:\xampp\htdocs\nuadu_helpdesk\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\GuardsAttributes.php:155
Illuminate\Database\Eloquent\FactoryBuilder::Illuminate\Database\Eloquent\{closure}()发布于 2020-09-07 11:04:10
我发现了我的问题。我使用auth和dd进行了检查。我在user_id中使用了不同的主键,它是一个字符串类型。我忘记在我的user.php中声明它
protected $primaryKey = 'user_id';
protected $keyType = 'string';
public $incrementing = false;默认情况下,主键始终是id。如果你声明了一个不同的列名作为你的主键,别忘了声明我上面提到的代码,否则你就不能读取auth或者不能登录了。
发布于 2020-09-03 23:48:53
在routes.php文件中,您不能写入要重定向的位置。所以请像下面这样添加..
Route::group(['middleware' => 'auth'], function() {
return redirect('/'); //by default you can change it as your requirments.
}https://stackoverflow.com/questions/63683649
复制相似问题