Laravel Sentinel外键

时间:2016-02-23 16:03:10

标签: laravel sentinel

我试图用Sentinel和Laravel 5注册一个人。“

Route::get('/', function () {

    $credentials = [
        'email'    => 'john.doe@example.com',
        'password' => 'password',
        'client_id' =>1,
    ];

    $user = Sentinel::register($credentials);
});`

我得到了这个回复

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a
 child row: a foreign key constraint fails (`dbmenubook`.`users`, CONSTRAINT 
`fk_users_me_clients1` FOREIGN 
KEY (`client_id`) REFERENCES `me_clients` (`id`) ON DELETE NO ACTION 
ON UPDATE NO ACTION) (SQL: insert into `users` 
(`email`, `password`, `updated_at`, `created_at`) values (john.doe@example.com,
y2016-02-23 
16:02:31fQMyg1raDBf/dNrQGQMe.LDxEHO5yQCA.J5cbZKmyuLKLYzzUIra, 
2016-02-23 
16:02:31, ?))

现在我正在尝试添加client_id,这会给我这个错误。但似乎client_id似乎没有被发送。我猜它与模型和可填充数组有关但这似乎是oke

用户模型

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */

    protected $table = 'users';
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

用户表

CREATE TABLE `users` (
  `id` int(10) unsigned NOT NULL,
  `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `permissions` text COLLATE utf8_unicode_ci,
  `first_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `last_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `client_id` int(10) unsigned NOT NULL,
  `last_login` timestamp NULL DEFAULT NULL,
  `ipad_id` int(10) DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=79 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

没有人知道问题是什么吗?

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题。

请检查您的/config/sentinel.cartalyst.php配置文件(如果您已发布)。

我发现那里的用户模型Sentinel是它的默认Eloquent模型,它没有必要的属性。

我已经创建了我的模型,扩展了默认的Sentinel Eloquent模型并实现了它的接口,添加了新的可填充字段数组并且有效。

我不确定这是最好和最合适的解决方案,但没有答案,我希望这个解决方案能为您提供帮助。