我将项目从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) 我'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)
我怎样才能用雄辩的关系做到这一点?
如何检查验证器用户名是否以字母开头?
return Validator::make($data, [
'username' => 'required|unique:users',
]);
Run Code Online (Sandbox Code Playgroud) 如何$this->team->playerAssignment->player更合理地检查现有财产?现在,我像这样检查它:
if ($this->team)
if (($this->team->playerAssignment))
if (($this->team->playerAssignment->player))
Run Code Online (Sandbox Code Playgroud) 我的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) laravel ×5
date ×1
eloquent ×1
exists ×1
foreign-keys ×1
migration ×1
properties ×1
timestamp ×1
unique ×1
validation ×1