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

abhishekregmi's avatar

API and Web in single project

I have a old website backend project/cms on laravel version 5.2 which run on web . My requirement is to make Api for same project. But there is no file of api.php . how can i make api in this project ? or should i rebuild it in latest laravel version ?

0 likes
2 replies
ramonrietdijk's avatar

I would definitely recommend to update or rebuild the application to the latest version. However, for the API question, you could add a new function to your RouteServiceProvider.

protected function mapApiRoutes()
{
    Route::group([
        'middleware' => 'api',
        'namespace' => $this->namespace,
        'prefix' => 'api',
    ], function ($router) {
        require app_path('Http/api.php');
    });
}

And call this method from within map.

Please or to participate in this conversation.