3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Eloquent\Modelのidはintにキャストされるようになった

Posted at

Laravel 5.2から、Modelのidは自動的にintにキャストされるようになったようです。

このため、$user->id === $task->user_id のような比較を行っている場合は注意が必要です($task->user_id側はデフォルトでは文字列となるため)。
明示的に (int) $user->id === (int) $task->user_id としてもよいですが、
Taskモデル側で $this->casts を指定しても良いでしょう。


class Task extends Model
{
    protected $casts = [
        'user_id' => 'int'
    ];
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?