nitiphone's avatar

Laravel, create a system for web and app in same code

Dear all, I have a project to create web app and mobile app so any way I can create a API on Laravel to support both web and app? for App, I understood but for web, could I use the laravel's blade for it? it's mean the web(html,css,js) and API in the same Laravel project

0 likes
6 replies
nitiphone's avatar

@webrobert now I can work on Laravel framework but just for web app and API in separate project. never combine them to the same project yet

webrobert's avatar

@nitiphone they use different middleware. generally you make controllers for api and/or controllers for web. Have a look at the middleware used...

Http/Kernel.php...

// The application's global HTTP middleware stack.
...

// The application's route middleware groups.
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
            'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
    ];

//The application's route middleware.
...

nitiphone's avatar

@webrobert So can I use API for support web and APP? they will call the same API, and can I put call the API for website from blade.php?

Please or to participate in this conversation.