'How to set current User class in controller (inherited from the main User class)
In my controller I want to access the extended class of the User class, but only in this controller and not in other controllers. Is there a way to set the User class per Controller?
The background: I have a global User Class which is for the whole project. In a special Controller I want to have access to an extended User class, so I can give the User class another relationship. This relationship is not necessary for the rest of the project.
Models:
class App\User extends Authenticatable implements MustVerifyEmail { ... }
class App\Special\User extends App\User {
public function myMethod(){}
}
Controller:
class SpecialController extends Controller {
public function myFunction(Request $request){
// This $user should get the App\Special\User
$user = Auth::user();
$user->myMethod();
}
}
Does anyone have an Idea how I can get this, without setting the global User class to the special User class and without putting myMethod in the global User class?
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
