我用這包加標籤系統錯誤
https://github.com/cviebrock/eloquent-taggable
得到錯誤當我嘗試在我的博客標籤
SQLSTATE [23000]:完整性約束違規:1048列「taggable_id」不能null(SQL:插入到
taggable_taggables
(created_at
,tag_id
,taggable_id
,taggable_type
,updated_at
)值(2016-07-05 21:24:20,1,,App \ blog,2016-07-05 21:24:20))
這裏是我的控制器
public function blogstore(Request $request){
$this->validate($request, [
'title' => 'required|max:255|unique:blogs',
'summary' => 'required',
'description' => 'required',
'image' => 'image',
'agree' => 'required',
]);
$blog = new blog;
$blog->title = $request->title;
$blog->summary = $request->summary;
$blog->content = $request->description;
$blog->user_id = Auth::user()->id;
$blog->slug = EasySlug::generateSlug($blog->title, $separator = '-');
$blog->tag('Apple,Banana,Cherry');
$blog->tag->taggable_id = 1;
if($request->hasFile('image')) {
$file = Input::file('image');
//getting timestamp
$timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
$name = $timestamp. '-' .$file->getClientOriginalName();
$blog->image = $name;
$file->move(public_path().'/../public_html/img/blog/', $name);
$thumb = Image::make(public_path().'/../public_html/img/blog/' . $name)->resize(1366,786)->save(public_path().'/../public_html/img/blog/thumb/' . $name, 90);
}
$blog->save();
return redirect()->route('admin.blog.index')->with('status', 'Blog Posted Successfully');
}
我理解它去空,但如何在這裏補充我的博客ID –