So the solution was to create a new ServiceProvider.
This solution works for Override
php artisan make:provider MyServiceProvider
Which extended the Vendor service provider (found within config/app.php). Within that ServiceProvider, add my alias within the overridden register method
$loader->alias('Vendor\VendorName\Class', 'App\Vendor\MyCustomClass');
Now, how do I extend the overridden class? I tried this:
$loader->alias('ClassParent', 'Vendor\VendorName\Class');
$loader->alias('Vendor\VendorName\Class', 'App\Vendor\MyCustomClass');
...
class MyCustomClass extends ClassParent {} // not working
First thing you need to do is extend the Vendor class:
class MyCustomClass extends Vendor\VendorName\Class {}
Now, this class has the properties and methods of the Vendor class and the properties and methods you've added.
Then, your custom class can become an alias:
$loader->alias('App\Vendor\MyCustomClass', 'Vendor\VendorName\Class');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.