'Convert type and id to model and use directly in controller

I often need to send request like see below to determine which model should be used.

{
    "type": "user", // or "company"
    "id": 2,    
    "otherData": "XY",  
}

I then have to check if the model with the id even exists and if the authenticated user is allowed to request this model. It would be great if I could retrieve the appropriate model directly in my controller instead of doing these checks each time in my controller.

Is there any way to do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source