我有一个BlogImage
模型和一个Blog
模型。现在,我想知道在关系中使用create
方法是否正确,以及为什么像下面这样使用它:
$blogImage = new BlogImage();
$blogImage->blog()->create([
//this is making the blog for me
'title' => $request->title,
'content' => $detail,
'category_id' => $request->category_id,
'author' => Auth::user()->id,
'meta_description' => $request->title,
'meta_image' => $meta_image,
]);
此外,我想知道此方法与正常形式之间的区别是什么:
Blog::create([
'title' => $request->title,
'content' => $detail,
'category_id' => $request->category_id,
'author' => Auth::user()->id,
'meta_description' => $request->title,
'meta_image' => $meta_image,
]);