我想使用另一个控制器保存信息以将其存储在数据库中。
在我的情况下,有两个控制器:
PostingsController
评论控制器
我可以使用 CommentsController 为评论创建创建函数,但我无法从 CommentsController 将 post_id 保存在数据库中。我想使用 PostingsController 保存 post_id,因为它具有:
//if user did not fill the form properly
//error messages will popup
$this->validate($request, [
'comment' => 'required',
]);
//if user filled the form properly
//store the form
$comment = new Comment();
//for connecting both user and comment
$comment->user_id = Auth::id();
//to store comment
$comment->post_id = //I want to save post_id from PostingsController
//to store comment
$comment->comment = $request->input('comment');
//save all user input
$comment->save();
dd($comment);
我设置了 $comment = Posting::id();,但它不起作用。错误是:
BadMethodCallException
Call to undefined method App\Models\Posting::id()
慕桂英4014372
阿波罗的战车