我有一个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,
]);
幕布斯7119047