I put model's business (as in "none of your business") in model's file. Let me explain with an example.
class Post extends Eloquent {
public function approved($isApproved)
{
$this->approved = $isApproved;
return $this;
}
}
class PostController extends BaseController {
public function setUnapproved($id)
{
Post::find($id)->approved(false)->save();
// redirect etc.
}
}
The reason I do it this way is for two reasons. First is, you may approve or unapprove posts from more than one place, right? No need to copy paste the same particular process everywhere. Second is, a controller doesn't have to know how to unapprove a post. Putting it in the model is also probably not the best way, we should use a repository or similar, but it is better than the controller way.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community