LoginSignup
1
0

More than 1 year has passed since last update.

【Laravel livewire】複合主キーのモデルで実装すると死ぬ

Posted at

概要

前提条件

  • Hogeモデルは複合主キーで実装されている
public Hoge $hoge;

public function mount()
{
    $this->hoge = Hoge:first();
}

livewireのコンポーネント内で複合主キーで作られたモデルを取得すると死ぬ。

array_key_exists(): Argument #1 ($key) must be a valid array offset type (View:

よくわからないがどっかのタイミングで単一の主キーを探してるみたい。誰か詳しく教えてください。

回避方法(やめた方がいい気がする)

public $hoge;

public function mount()
{
    $this->hoge = Hoge:first()->toArray();
}

型の宣言をやめて只の配列として取得すれば回避出来るっちゃ出来るが、複合種キーじゃ無いとダメ!とかではないなら一意のid持とう

理想

複合主キー辞めてサロゲートキーで実装しよう。
僕はそうしようと思う。

1
0
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
1
0