我有一个名为CreatePost的组件
class CreatePost extends Component
{
public PostForm $form;
public function save()
{
$this->form->store();
return $this->redirect('/posts');
}
}
下面是我的POSTFORM:
class PostForm extends Form
{
public $title = '';
public $content = '';
public function store()
{
$this->validate();
Post::create($this->all());
}
}
现在,在我的PostForm store()方法中,我想注入我的PostService来创建一个Post.做这件事最好的方法是什么?
谢谢
我能想到的最好方法是将postService注入组件的ot()方法中,然后将其作为参数传递到store()中,但我希望是否有更干净的方法来完成这项工作,例如通过ServiceProvider?