내가 피벗 테이블에 데이터를 기록하려고하지만 난 를 얻을이 내가 갈거야 내 코드입니다Laravel 삽입
"널 (null)의 멤버 함수 손님()에 전화" 잘못된?
나는이 시도하고 내가 무슨 잘못
이벤트 모델
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Event extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'events';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['headline', 'description', 'address', 'zip', 'longitude', 'latitude',
'position', 'country_id', 'cat_id', 'start_date', 'end_date'];
public function user()
{
return $this->belongsTo('App\User');
}
/**
* The products that belong to the shop.
*/
public function guests()
{
return $this->belongsToMany('App\Models\Guest', 'event_guest', 'guest_id', 'event_id');
}
}
고객 모델
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Guest extends Model
{
protected $fillable = ['first_name', 'last_name', 'email'];
public function events()
{
return $this->belongsToMany('App\Models\Event', 'event_guest', 'event_id', 'guest_id');
}
}
컨트롤러
,369에 혼란 스러워요//RSVP events
public function rsvpCheck()
{
$check = Guest::find(5);
//$guestCheck = Event::where('id',5)->first();
$check->events()->attach(2);
return $check->events;
}
은 어디'guest' 방법을 callig하는 피벗 테이블에 삽입 할 필요가? – jaysingkar
이벤트 모델'public function guests() { return $ this-> belongsToMany ('App \ Models \ Guest', 'event_guest', 'guest_id', 'event_id'); }' – Didi
어디서 정의 할 것인가? – tam5