Laravel for Beginners – Learn to Build Full-Stack Web Apps

Loading video...

Configuration

Getting Started With Laravel

Configuration

Laravel 11 comes with several configuration files out of the box. Many configuration options are available in .env file as well.

If you don’t need to modify these configuration files feel free to delete them, the default files exist in vendor folder in Laravel’s core and they will be used from core.

In order to create configuration files for different services in Laravel 11 you have to publish the configuration file you need by artisan command: php artisan config:publish

This will give you the following screen and you need to type the configuration file name, like: app, or broadcasting

Untitled

If you know exactly which configuration file you want to publish you can directly execute php artisan config:publish [FILE_NAME].

Example: php artisan config:publish app

Let’s say you published cors configuration file. The content of the file looks like this.

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Cross-Origin Resource Sharing (CORS) Configuration
    |--------------------------------------------------------------------------
    |
    | Here you may configure your settings for cross-origin resource sharing
    | or "CORS". This determines what cross-origin operations may execute
    | in web browsers. You are free to adjust these settings as needed.
    |
    | To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
    |
    */

    'paths' => ['api/*', 'sanctum/csrf-cookie'],

    'allowed_methods' => ['*'],

    'allowed_origins' => ['*'],

    'allowed_origins_patterns' => [],

    'allowed_headers' => ['*'],

    'exposed_headers' => [],

    'max_age' => 0,

    'supports_credentials' => false,

];

If you want to only customize a single configuration line (Ex: Change supports_credentials into true), you can just leave only that option and delete others. So your final config/cors.php file will look like this.

<?php

return [

    'supports_credentials' => true,

];

Discussion

Sign in to join the discussion.

No comments yet. Be the first to start the discussion!