
前の質問で提案された一対多対多のリレーションを組みたいのですが、eventテーブルの値が取得できません。
モデルは以下の通りなのですが、何処を修正すればいいのでしょうか。
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->hasMany('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 = 'point'; 10 11 public function customer() 12 { 13 return $this->belongsTo('App\Customer', 'customer_id', 'id'); 14 } 15 16 public function students() 17 { 18 return $this->belongsToMany('App\Event', 'App\Point_Event', 'point_id', 'event_id'); 19 } 20}
Event.php
php
1<?php 2 3namespace App; 4 5use Illuminate\Database\Eloquent\Model; 6 7class Event extends Model 8{ 9 protected $table = 'event'; 10 11 public function courses() 12 { 13 return $this->belongsToMany('App\Point', 'App\Point_event', 'event_id', 'point_id'); 14 } 15}
Point_Event.php(中間モデル)
php
1<?php 2 3namespace App; 4 5use Illuminate\Database\Eloquent\Model; 6 7class Point_Event extends Model 8{ 9 protected $table = 'oint_event'; 10}
回答2件
あなたの回答
tips
プレビュー