小编Igo*_*iuk的帖子

升级到laravel 5.3后出错无效日期时间格式:1292日期时间值不正确:'0000-00-00 00:00:00'

我将项目从5.2升级到laravel 5.3.现在,当我想要运行时,php artisan migrate我收到错误:SQLSTATE [22007]:无效的日期时间格式:1292日期时间值不正确:第1行的'created_at'列的'0000-00-00 00:00:00'(SQL:alter table messagesadd deleted_attimestamp空值).我的迁移:

  Schema::table(Models::table('messages'), function (Blueprint $table) {
        $table->softDeletes();
  });
Run Code Online (Sandbox Code Playgroud)

在Blueprint.php中:

    public function softDeletes()
    {
        return $this->timestamp('deleted_at')->nullable();
    }
Run Code Online (Sandbox Code Playgroud)

migration timestamp date laravel

8
推荐指数
2
解决办法
8634
查看次数

BelongsToMany 关系。如何获得唯一的行

'member_companies'在数据库中有下一个表:

在此处输入图片说明

并且在模型 Member 中有一个关系:

public function companies()
{
    return $this->belongsToMany(Company::class, 'member_companies');
}
Run Code Online (Sandbox Code Playgroud)

它返回给我所有有重复的公司。例如,Member::find(238)->companies->pluck('id')返回

[
  6,
  5,
  7,
  2,
  10,
  8,
  4,
  13,
  14,
  10,
  8,
  13
]
Run Code Online (Sandbox Code Playgroud)

但我只想要独特的物品。喜欢

[
    6,
    5,
    7,
    2,
    10,
    8,
    4,
    13,
    14,
]   
Run Code Online (Sandbox Code Playgroud)

我怎样才能用雄辩的关系做到这一点?

unique has-and-belongs-to-many laravel eloquent

6
推荐指数
2
解决办法
4391
查看次数

Laravel 验证第一个符号

如何检查验证器用户名是否以字母开头?

return Validator::make($data, [
    'username' => 'required|unique:users',
]);
Run Code Online (Sandbox Code Playgroud)

validation laravel

2
推荐指数
1
解决办法
2084
查看次数

Laravel检查属性存在

如何$this->team->playerAssignment->player更合理地检查现有财产?现在,我像这样检查它:

if ($this->team)
   if (($this->team->playerAssignment))
      if (($this->team->playerAssignment->player))
Run Code Online (Sandbox Code Playgroud)

properties exists laravel

1
推荐指数
1
解决办法
4932
查看次数

Laravel 5.5 不能掉外来

我的trophies表:

public function up()
{
    Schema::create('trophies', function (Blueprint $table) {
        $table->increments('id');

        $table->integer('tournament_id')->unsigned()->nullable();
        $table->foreign('tournament_id')
            ->references('id')
            ->on('tournaments')
            ->onUpdate('cascade')
            ->onDelete('cascade')
        ;

        $table->integer('season_id')->unsigned()->nullable();
        $table->foreign('season_id')
            ->references('id')
            ->on('seasons')
            ->onUpdate('cascade')
            ->onDelete('cascade')
        ;

        $table->integer('user_id')->nullable()->unsigned();
        $table->foreign('user_id')
            ->references('id')
            ->on('users')
            ->onUpdate('cascade')
            ->onDelete('cascade');
        ;

        $table->integer('team_id')->nullable()->unsigned();
        $table->foreign('team_id')
            ->references('id')
            ->on('teams')
            ->onUpdate('cascade')
            ->onDelete('cascade')
        ;
        $table->timestamps();
    });
}
Run Code Online (Sandbox Code Playgroud)

现在我想删除外键 season_id

public function up()
{
    Schema::table('trophies', function (Blueprint $table) {
        $table->dropForeign(['season_id']);
    });
}
Run Code Online (Sandbox Code Playgroud)

当我运行 php artisan migrate 时,我收到下一个错误:

In Connection.php line 664:

  SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'trophies_season_id_foreign'; check that column/key …
Run Code Online (Sandbox Code Playgroud)

foreign-keys laravel

0
推荐指数
1
解决办法
2842
查看次数