Recent Topics

Override Route



  • How can i override route in filter, where can i see them?



  • Hi @admin

    Can you explain little bit more ?

    Thanks



  • For example, I want to override the default page for a certain category.

    So I extend the controller within my own package:

    class ProductsCategoriesProxyController extends \Webkul\Shop\Http\Controllers\ProductsCategoriesProxyController
    {
    

    In that packages routes file, I override the route:

    Route::fallback(\MyCompany\MyPackage\Http\Controllers\ProductsCategoriesProxyController::class . '@index')
           ->defaults('_config', [
               'product_view' => 'shop::products.view',
               'category_view' => 'shop::products.index'
           ])
           ->name('shop.productOrCategory.index')
    

    Now, the question is, how do I make sure that this route, in the packages/MyCompany/MyPackage/src/Http/routes.php ALWAYS SUPERCEDES the route already defined in packages/Webkul/Shop/src/Http/routes.php ?



  • Hello @iateadonut

    For overriding purpose you can override the route.php.

    First you have to make the copy of the file in your package which you want to override then make changes in that file then go to your serviceprovider.php file and write this code in boot() method

      $this->publishes([__DIR__ . 'path-where-file-is-located-in-your-package' => 'path-of-file-which- you-want-to-overide' ]);
    

    After that you can run php artisan vendor:publish --force and select your package.

    This will override the existing file and from that you package controller index will work.

    Thank you. Hope this will work for you.

    Deepak Singh Gusian


Log in to reply