[英]Call to undefined method Illuminate\Database\Query\Builder::attach() In laravel 5.3
I need help with this error 我需要帮助解决这个错误
Call to undefined method Illuminate\\Database\\Query\\Builder::attach() 调用未定义的方法Illuminate \\ Database \\ Query \\ Builder :: attach()
my Model is 我的模型是
public function casts()
{
return $this->belongsToMany(Cast::class)->withTimestamps();
}
My Controller 我的控制器
public function addCast(Request $request, $id)
{
$this->validate($request, [
'casts' => 'required'
]);
$show = $this->shows->findOrFail($id);
$show->photos()->attach($request->input('casts'));
dd($show);
}
my Form 我的表格
<form action="{{ route('shows.addCasts', $show->id) }}" method="POST">
{{ csrf_field() }}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title"><img src="{{ Storage::url($show->small_image) }}" height="30" width="30">{{ $show->name }}</h4>
</div>
<div class="modal-body">
<div class="form-group">
{!! Form::label('casts') !!}
{{ Form::select('casts[]', $casts, null, ['class' => 'form-control roles']) }}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
{!! Form::submit('Save Cast', ['class' => 'btn btn-primary']) !!}
{{--<button type="submit" class="btn btn-primary">Save changes</button>--}}
</div>
</form>
can anybody tell my what i did wrong or if you guys have any solution Thank for your help 任何人都可以告诉我我做错了什么或者你们有什么解决方案感谢您的帮助
The other side of the relationship also needs to be a belongsToMany as the attach method is for many to many relationships - see an already answered post on this: 关系的另一面也需要是belongsToMany,因为attach方法适用于多对多的关系 - 请参阅已经回答的帖子:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.