Laravelで以下の表の様なリレーションをする為モデルを作成したのですが、customer_pointテーブルとcustomer_point_detailテーブルをどう連携すればいいのか分かりません。
モデルは以下のように定義したのですが、Detailにはどのようなアノテーションを付与すれば表の様なリレーションが実行できるでしょうか
Customer.php
php
1<?php 2 3namespace App; 4 5use Laravel\Passport\HasApiTokens; 6use Illuminate\Notifications\Notifiable; 7use Illuminate\Foundation\Auth\User as Authenticatable; 8 9class Customer extends Authenticatable 10{ 11 use HasApiTokens, Notifiable; 12 13 /** 14 * The table associated with the model. 15 * 16 * @var string 17 */ 18 protected $table = 'customer'; 19 20 protected $with = 'point'; 21 22 public function point() 23 { 24 return $this->hasone('App\Point'); 25 } 26 27 /** 28 * The attributes that are mass assignable. 29 * 30 * @var array 31 */ 32 protected $fillable = [ 33 'name', 'email', 'password', 34 ]; 35 36 /** 37 * The attributes that should be hidden for arrays. 38 * 39 * @var array 40 */ 41 protected $hidden = [ 42 'password', 'remember_token', 43 ]; 44 45 /** 46 * The attributes that should be cast to native types. 47 * 48 * @var array 49 */ 50 protected $casts = [ 51 'email_verified_at' => 'datetime', 52 ]; 53}
Point.php
php
1<?php 2 3namespace App; 4 5use Illuminate\Database\Eloquent\Model; 6 7class Point extends Model 8{ 9 protected $table = 'customer_point'; 10 11 protected $primaryKey = 'customer_id'; 12 13 public function customer() 14 { 15 return $this->belongsto('App\Customer'); 16 } 17}
Detail.php
php
1<?php 2 3namespace App; 4 5use Illuminate\Database\Eloquent\Model; 6 7class Point extends Model 8{ 9 protected $table = 'customer_point_detail'; 10}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/03 08:14
2019/08/03 08:43
2019/08/03 15:24
2019/08/03 17:51
2019/08/03 20:44