I have my controllers split in 2 sections: App/Http/Controllers
& App/Api/Controllers
. Most of these controllers have 4/5 methods in common, and nothing changes between them apart from the Eloquent Model name e.g. User
How can I abstract these methods away into their own controller that the other controllers can extend and still use Eloquent? Is there any method I've missed that can provide the Eloquent name of the parent controller?
I thought about just setting a var like `modelName = 'User' and using that with var vars, but I would prefer a completely "lazy" solution where I don't have variable to change.
Pseudo Example:
<?php
class ApiController extends Controller
{
public function index()
{
$model = ParentModelName::all();
return response()->json($model);
}
}