davzie / laravel-bootstrap

[DEPRECATED] A Laravel 4, Bootstrap 3 CMS Built With SOLID Principles In Mind
Other
558 stars 171 forks source link

How to overwrite getAll() #33

Closed lgt closed 10 years ago

lgt commented 10 years ago

So I've been following the patterns and I made a custom Class, Interface and on getAll I would like to override the query like

return $this->model->where('id',$id)->get();

How would I do that?

davzie commented 10 years ago

getAll is a base method. 

So in your repository you would simply do

    public function getAll()
    {
        return $this->model->where(‘id’,$id)->get();
    }

I can’t see where you’d want $id defined though.

Additionally with the base-repository commands you could probably just do

    public function getAll()
    {
        return $this->getById($id);
    }

Hope that helps!

Dave

lgt commented 10 years ago

Thanks for your fast reaction. I pass the ID via url like /propertyrooms/1 where 1 is the the ID of the referenced property, and would be good to know how to catch that id if in the router I have

Route::controller( $urlSegment.'/rooms/{id}'     , 'Davzie\LaravelBootstrap\Controllers\RoomsController' );

. I will give another try with your advised and thank you for your feedback