Модель элемента:
Код: Выделить всё
public function events()
{
return $this->belongsToMany('App\Event', 'event_item');
}
Код: Выделить всё
public function items()
{
return $this->belongsToMany('App\Item', 'event_item');
}
Код: Выделить всё
public function items()
{
return $this->hasMany('App\Item', 'user_id');
}
Код: Выделить всё
public function store(Request $request)
{
// Get user
$user = $request->user();
// Create event
$event = Event::create(array_merge($request->all(), ['user_id' => $user->id]));
// Attach items to event
$user->items()->attach($event->id);
}
Я получаю эту ошибку. Метод Illuminate\Database\Query\Builder::attach не существует.
Подробнее здесь: https://stackoverflow.com/questions/560 ... -not-exist