2

I am using Laravel 5.8 and I'm attempting to modify a package class from the Vendor directory. To acheive this, I have created a new class which extends the Vendor class, and I can replace the named functions within it- all working great.

However, the original class 'uses' a class, which I have mimicked in my new class, as follows:

use VendorName\PackageName\OriginalController

// use VendorName\PackageName\SomeClass as StoreRequest; How can I replace this...
use App\Http\Requests\NewRequestClass as StoreRequest; // ... with this..? (not working)

class NewController extends OriginalController {

    private function somefunction(StoreRequest $request){ // This doesn't work; it is still using the StoreReqest defined in OriginalController
        // ...
    }

}

See comments- Is it possible to override this?

Inigo
  • 8,110
  • 18
  • 62
  • 110
  • 1
    I've never actually tried this, but I suspect you might be able to do this by setting up a custom autoloader to specifically catch when the original class is requested and load in your own file – rickdenhaan Aug 04 '19 at 18:01
  • Does your `NewRequestClass` extend `StoreRequest`? – lufc Aug 04 '19 at 18:26

1 Answers1

0

Its generally not possible modify/delete class or function. Not without extensions like Classkit. But i am not really a fan of this type of code. But you can Check these questions, which might help:

ezio4df
  • 3,541
  • 6
  • 16
  • 31