BaseController seems a good place. I would also suggest looking for design patterns, creating basic APIs or traits if you use PHP 5.4.
May I ask why this need's to be in every controller? If you had like
protected $table = 'blablabla';
it would make sense (but would be misplaced) but since you post the type anyway, wouldn't it just be simpler to have 1 url/method for that instead?
This doesn't seem very safe. Your injecting that variable straight in the query, instead of binding parameters. You can create a BaseController with this function, use Trait with this method or use Eloquent Models and add a trait there, and just call that method in all your controllers.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.