I have two Guards
Admin
User
Also i have created controllers where user can manage his own data and admin can also manage user data. So i created two Controllers
Controllers
Admin
EducatonBackgroundController
User
EducationBackgroundController
In User/EducationBackgroundController i have this function which fetch education background of a current logged user and display on the user view
public function index(Education $education)
{
try {
$educations = $education->where('user_id',$this->userLoggedID())->with('organization','program','country','city')->get();
return view('users.education.index',compact('educations'));
}
catch (Exception $e) {
abort(404);
}
}
In Admin/EducationBackgroundController i have this function which fetch education background of all users and display on the admin view
public function index(Education $education)
{
try {
$educations = $education->with('organization','program','country','city','user')->get();
return view('admin.users.education.index',compact('educations'));
}
catch (Exception $e) {
abort(404);
}
}
From observation these functions are similar but differ on view return and data fetch.
So How can i create a one Controller which can be used by both Admin and User guards instead of duplicate Controller and View for both Guards.