Automatically run and return when resolving a class?

  laravel, php

I have a service that is injected into my controller:

public function store(AppServicesPolymorphicService $poly) {

    $poly->resolveClass();

Inside this service class I have some code that resolves POST data and returns a specific class.

For example:

resolveClass() {
     // do logic
     // return class
}

Is there a way to automatically run the method poly->resolveClass(); and have that returned on the injection part:

public function store(AppServicesPolymorphicService $poly) {

Instead of having to manually call my method?

Source: Laravel

Leave a Reply