Request fields in Model

Posted 2 years ago by fdusautoir

Hello Everybody,

I wonder if I took the right way in my application. For example, in my FooController I have :


public function submit(Foo $foo)
{
    $foo->submit();
    return back();
}


public function publish(Foo $foo)
{
    $foo->publish();
    return back();
}

And in my Foo model :


      private function updateFields($status)
    {
        $this->update([
            'body'        => request('body'),
            'body_draft'  => request('body'),
            'status'     => $status,
            'difficulty' => request('difficulty') ?: $this->difficulty,
            'comment'    => request('comment') ?: $this->comment,
        ]);
    }
    
    public function submit()
    {
        $this->updateFields('submit');
        $this->archive('submit');
    }
    
    public function publish()
    {
        $this->updateFields('publish');
        $this->archive('publish');
    }


All is working well but is it a good way to proceed or it not recommend to use request in model and why ?

Thanks for your help ! :)

Please sign in or create an account to participate in this conversation.