Yea, stop with model binding and use the repository ;) Model binding is cool if you need to be quick but it doesn't make any sence in some cases!
Jun 12, 2015
3
Level 1
Route model binding VS repository. Can they live together?
I have a controller. It has some methods with quite complex queries (like pagination) and also some very simple methods with trivilar queries (like destroy). It feels correct to put pagination logic in repository, however, I'm not sure what to do with the rest of controller methods which are trivial.
I could use Route Model Bindings:
public function destroy( Item $item )
{
$item->delete();
return redirect()->back()->withSuccess( 'Item deleted' );
}
However, the code above creates a hard dependency between Controller and Model. This could be solved with a repo like this:
public function destroy( $id )
{
$this->repository->deleteById($id);
return redirect()->back()->withSuccess( 'Item deleted' );
}
It kinda feels bad to mix route model binding together with repositories and I should probably stop using route model binding in favour of repos. Is that right?
Level 88
Please or to participate in this conversation.