Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davy_yg's avatar
Level 27

Can't find the api

Hello this is strange that I cannot find where the api is located?

 methods : {
        getSku: function () {
            axios
                .get('/productInventory/get-all-sku')
                .then(response => {
                   this.list_sku = response.data;
                });
        },

If I type on the browser: http://127.0.0.1:8000/productInventory/get-all-sku

I can see the api.

As far as I know all api address should be listed here:

routes/api.php

<?php

use Illuminate\Http\Request;

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::get('/search', 'SearchController@index')->name('cari.barang');
Route::get('/checkphone', 'SearchController@checkPhone')->name('cari.telepon');
Route::get('/checkemail', 'SearchController@checkEmail')->name('cari.email');

//product or price
Route::get('/stock/{priceId}', 'StockController@checkStock')->name('cari.email');

I wonder why this api : .get('/productInventory/get-all-sku')

Is not listed in the routes/api.php and still works just fine?

0 likes
13 replies
Nakov's avatar

It might be because it is listed in the web.php file, as that's not an API route at all :)

or just check your routes folder and make sure there is no additional file in there that loads those routes.

davy_yg's avatar
Level 27

It's not anywhere in my routes folder.

There is another thing: this path works just fine: http://127.0.0.1:8000/productInventory/create

Yet, the routes is not listed in any file in my routes folder: productInventory/create

I search my whole web project:

Searching 60561 files for "/productInventory/create"

0 matches

This is strange.

Nakov's avatar

@davy_yg routes that exist in the api.php file will be prefixed with /api/ this one is not so it will not be there for sure..

Do you maybe can find :

Route::resource('productInventory' .. );

Run php artisan route:list it will show you a table of all the routes registered in the project. Make sure you are looking at the correct project as well :)

btw this route /productInventory/get-all-sku will work if the ProductInventory overrides the getRouteKeyName method, so it uses slug instead of an ID.

davy_yg's avatar
Level 27

I finally find where it is located:

modules/ProductInventory/Routes/web.php

Route::group(
[
    'prefix' => '',
    'as' => '',
    'middleware' => ['web', 'auth'],
],
function () {
    Route::resource('productInventory', 'ProductInventoryController')
        ->only('index', 'create', 'store');

    Route::get('productInventory/template-stock', 'ProductInventoryController@templateStock')
        ->name('productInventory.templateStock');

    Route::get('productInventory/get-all-sku', 'ProductInventoryController@getAllSku')
        ->name('productInventory.getAllSku');

    Route::get('productInventory/get-product/{sku}', 'ProductInventoryController@getProductCatalog')
        ->name('productInventory.getProductCatalog');

    Route::get('productInventory/get-stock-bulk', 'ProductInventoryController@getBulkStock')
        ->name('productInventory.get-stock-bulk');

    Route::get('productInventory/get-stock-bulk-data', 'ProductInventoryController@getBulkStockData')
        ->name('productInventory.get-stock-bulk-data');

    Route::post('productInventory/post-stock-bulk', 'ProductInventoryController@postBulkStock')
        ->name('productInventory.post-stock-bulk');

    Route::post('productInventory/proses-stock-bulk', 'ProductInventoryController@prosesBulkStock')
        ->name('productInventory.proses-stock-bulk');
}
);

If I have modules folder in my root project directory will it automatically read the modules/ProductInventory/Routes/web.php ?

Sinnbeck's avatar

I dont think so no. Check your RouteServiceProvider. I bet it is loading that file.

Nakov's avatar

@davy_yg open your RouteServiceProvider.php class, I bet there this file is being located.

Automatically it won't load unless you tell it so. That's how the default web.php and api.php are loaded as well.

davy_yg's avatar
Level 27

Which RouteServiceProvider.php?

modules/ProductInventory/Providers/RouteServiceProvider.php

<?php

namespace Modules\ProductInventory\Providers;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;

class RouteServiceProvider extends ServiceProvider
{
    /**
    * The module namespace to assume when generating URLs to actions.
    *
    * @var string
    */

protected $moduleNamespace = 'Modules\ProductInventory\Http\Controllers';

/**
    * Called before routes are registered.
    *
    * Register any model bindings or pattern based filters.
    *
    * @return void
    */

public function boot()
    {
    parent::boot();
    }

    /**
    * Define the routes for the application.
    *
    * @return void
    */
    
public function map()
    {
    $this->mapWebRoutes();
    }

    /**
    * Define the "web" routes for the application.
    *
    * These routes all receive session state, CSRF protection, etc.
    *
    * @return void
    */

protected function mapWebRoutes()
    {
    Route::middleware('web')
        ->namespace($this->moduleNamespace)
        ->group(__DIR__ . '/../Routes/web.php');
    }   
}

app/Providers/RouteServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\URL;

class RouteServiceProvider extends ServiceProvider  
{
    /**
    * This namespace is applied to your controller routes.
    *
    * In addition, it is set as the URL generator's root namespace.
    *
    * @var string
    */

    protected $namespace = 'App\Http\Controllers';

    /**
    * Define your route model bindings, pattern filters, etc.
    *
    * @return void
    */
    
public function boot()
    {
    if ($this->app->environment('production', 'staging')) {
        URL::forceScheme('https');
    }

    parent::boot();
    }

 /**
    * Define the routes for the application.
    *
    * @return void
    */

public function map()
    {
    $this->mapApiRoutes();

    $this->mapWebRoutes();

    //
    }

    /**
    * Define the "web" routes for the application.
    *
    * These routes all receive session state, CSRF protection, etc.
    *
    * @return void
    */

protected function mapWebRoutes()
    {
    Route::middleware('web')
         ->namespace($this->namespace)
         ->group(base_path('routes/web.php'));
    }

    /**
    * Define the "api" routes for the application.
    *
    * These routes are typically stateless.
    *
    * @return void
    */

protected function mapApiRoutes()
    {
    Route::prefix('api')
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(base_path('routes/api.php'));
    }
}

I think the default laravel RouteServiceProvider.php still remains default.

Nakov's avatar

@davy_yg this one:

modules/ProductInventory/Providers/RouteServiceProvider.php

You can see which one it loads the correct file :) so that one is also registered in config/app.php file.

davy_yg's avatar
Level 27

Now, I understand about how to register the Routes/web.php part. Now, what about the controller?

ServiceProvider.php

<?php

namespace Modules\BankAccount\Providers;

use Illuminate\Database\Eloquent\Factory;

class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
    /**
    * Boot the application events.
    *
    * @return void
    */

public function boot()
    {
    $this->registerMenu();
    $this->registerTranslations();
    $this->registerConfig();
    $this->registerViews();
    $this->registerFactories();
    $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
    }

    /**
    * Register the service provider.
    *
    * @return void
    */

public function register()
    {
    $this->app->register(RouteServiceProvider::class);
    }

    /**
    * Register menu.
    *
    * @return void
    */

protected function registerMenu()
    {
    // if ($this->app->bound('laravolt.menu')) {
    //     $parent = app('laravolt.menu');

    //     $parent->add('Bank Account', route('bankAccount.index'))
    //         ->data('icon', 'circle outline')
    //         ->active('bank-account/*');
    // }
    }

    /**
    * Register config.
    *
    * @return void
    */

protected function registerConfig()
    {
    $this->publishes([
        __DIR__ . '/../Config/config.php' => config_path('bankAccount.php'),
    ], 'config');
    $this->mergeConfigFrom(
        __DIR__ . '/../Config/config.php',
        'bankAccount'
    );
    }

    /**
    * Register views.
    *
    * @return void
    */

public function registerViews()
 {
    $viewPath = resource_path('views/modules/bankAccount');

    $sourcePath = __DIR__ . '/../Resources/views';

    $this->publishes([
        $sourcePath => $viewPath
    ], 'views');

    $this->loadViewsFrom(array_merge(array_map(function ($path) {
        return $path . '/modules/bankAccount';
    }, \Config::get('view.paths')), [$sourcePath]), 'bankAccount');
    }

    /**
    * Register translations.
    *
    * @return void
    */

public function registerTranslations()
    {
    $langPath = resource_path('lang/modules/bankAccount');

    if (is_dir($langPath)) {
        $this->loadTranslationsFrom($langPath, 'bankAccount');
    } else {
        $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'bankAccount');
    }
    }

    /**
    * Register an additional directory of factories.
    *
    * @return void
    */

public function registerFactories()
    {
    if (! app()->environment('production')) {
        app(Factory::class)->load(__DIR__ . '/../Database/factories');
    }
    }

    /**
    * Get the services provided by the provider.
    *
    * @return array
    */

public function provides()
    {
    return [];
    }
}

In this case, it seems like the other dev do not register the controller as we do not use it. I am just supposing if in the future I need the module controller as well? So it's possible to register it and make the program read the module controller as well right? Looks like the view is also registered. But I do not see the point of registering it? since the controller that controls the view is not registered.

Nakov's avatar

@davy_yg and on and on we go with different questions :)

Route::resource('productInventory', 'ProductInventoryController')
        ->only('index', 'create', 'store');

this is how you register the controller, so it is used..

Please read the documentation.. You took a huge project and you've never read a page of the documentation nor watched any video I guess.

davy_yg's avatar
Level 27

Registering controller is through routes then it is not through service provider, correct? I read the service provider doc already.

ref: https://laravel.com/docs/6.x/providers

watching videos on related topic is a good idea.

Nakov's avatar
Nakov
Best Answer
Level 73

@davy_yg good job understanding that :)

So you see in the RouteServiceProvider of the module this part:

protected $moduleNamespace = 'Modules\ProductInventory\Http\Controllers';

Route::middleware('web')
        ->namespace($this->moduleNamespace)
        ->group(__DIR__ . '/../Routes/web.php');

This tells it to load the controllers from that namespace. So when you say in the route ProductInventoryController

It will try to find the controller in: 'Modules\ProductInventory\Http\Controllers\ProductInventoryController.php'.

Please or to participate in this conversation.