Skip to content

Instantly share code, notes, and snippets.

@medaminebt
Last active August 14, 2024 09:47
Show Gist options
  • Save medaminebt/2f5aa29de85106550a8d50d1d9dfe472 to your computer and use it in GitHub Desktop.
Save medaminebt/2f5aa29de85106550a8d50d1d9dfe472 to your computer and use it in GitHub Desktop.
APP_NAME=Elearny
APP_ENV=local
APP_KEY=base64:F3lX2XiWbULtR5SwZnR4TNVn/E93S1Fg/lMepg6vxWg=
APP_DEBUG=true
APP_URL=https://elearning.theteam.com.tn
FRONTEND_URL=https://cool-napier.85-215-138-217.plesk.page
#https://elearning.theteam.com.tn
#http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laraveldb
DB_USERNAME=admin-db
DB_PASSWORD=Azerty123456%
#BROADCAST_DRIVER=log
#CACHE_DRIVER=file
#FILESYSTEM_DISK=local
#QUEUE_CONNECTION=sync
#SESSION_DRIVER=file
#SESSION_LIFETIME=120
MODEL_CACHE_STORE=array
BROADCAST_DRIVER=log
CACHE_DRIVER=array
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
#127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=ssl0.ovh.net
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
#MAIL_MAILER=smtp
#MAIL_HOST=mailpit
#MAIL_PORT=1025
#MAIL_USERNAME=null
#MAIL_PASSWORD=null
#MAIL_ENCRYPTION=null
#MAIL_FROM_ADDRESS="[email protected]"
#MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1
VITE_APP_NAME="${APP_NAME}"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
# new 12-06-24
JWT_SECRET=J85WDsrFxwPyfSX8AK3JGumGLIVQ6gJsB2YK4khx8AvsElt5JmLhfybklkDKgEq0
RESPONSE_CACHE_DRIVER=array|redis|memcached

Laravel

Commands

composer install
composer dump-autoload
composer update

Database Schema Generation

php artisan serve --port=8020
php artisan migrate
php artisan migrate --seed
php artisan migrate:refresh
php artisan migrate:refresh --seed



.env server theteam :

php artisan serve --port=8020 --host=0.0.0.0




When quizzes table is deleted :

php artisan make:migration create_quizzes_table
php artisan migrate

  • To Double Check :
    • Migration Status: You can check the status of your migrations using the command:
    • Rollback & Re-migrate: If needed, you can rollback the last batch of migrations (which will drop the tables) and then re-run them.
php artisan migrate:status
php artisan migrate:rollback
composer require barryvdh/laravel-ide-helper





https://stackoverflow.com/questions/68515548/phpstorm-says-find-method-not-found

https://techvblogs.com/blog/laravel-10-crud-example-tutorial-for-beginners

@medaminebt
Copy link
Author

php artisan vendor:publish --provider="Fruitcake\Cors\CorsServiceProvider"

@medaminebt
Copy link
Author

To ensure that files uploaded through your application have the correct permissions, you need to configure your Laravel application to set the appropriate permissions when saving files. Additionally, resolving the CORS issue is crucial.

Step 1: Ensure Correct File Permissions on Upload

You can set the file permissions when saving files in Laravel. Here’s how you can do it:

  1. Open your file upload logic:
    If you have a controller or service handling file uploads, you can set the permissions there. For example:

    // Assuming you're using the default storage disk
    $path = $request->file('your_file_input')->store('public/files');
    
    // Get the full path to the file
    $fullPath = storage_path('app/' . $path);
    
    // Set the file permissions to 0644 (readable by everyone)
    chmod($fullPath, 0644);
  2. Example in Controller:

    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    
    class FileUploadController extends Controller
    {
        public function upload(Request $request)
        {
            // Validate the request...
            $validated = $request->validate([
                'file' => 'required|file|mimes:jpg,jpeg,png,gif',
            ]);
    
            // Store the file
            $path = $request->file('file')->store('public/files');
    
            // Set permissions to be readable by everyone
            $fullPath = storage_path('app/' . $path);
            chmod($fullPath, 0644);
    
            return response()->json(['path' => $path], 200);
        }
    }

Step 2: Fix CORS Issue

Ensure the fruitcake/laravel-cors package is correctly configured and headers are set properly.

  1. Install the package:

    composer require fruitcake/laravel-cors
  2. Publish the configuration:

    php artisan vendor:publish --provider="Fruitcake\Cors\CorsServiceProvider"
  3. Configure config/cors.php:

    return [
    
        'paths' => ['api/*', 'storage/*'],
    
        'allowed_methods' => ['*'],
    
        'allowed_origins' => ['https://cool-napier.85-215-138-217.plesk.page'],
    
        'allowed_origins_patterns' => [],
    
        'allowed_headers' => ['*'],
    
        'exposed_headers' => ['Authorization', 'Content-Type'],
    
        'max_age' => 0,
    
        'supports_credentials' => false,
    
    ];
  4. Ensure the middleware is registered in app/Http/Kernel.php:

    protected $middleware = [
        // other middleware
        \Fruitcake\Cors\HandleCors::class,
    ];
  5. Clear configuration cache:

    php artisan config:clear
    php artisan cache:clear

Step 3: Verify Web Server Configuration

Ensure that your web server is configured to allow CORS headers:

  • For Nginx:

    Add the following in your server block:

    server {
        // other configurations
    
        location / {
            add_header 'Access-Control-Allow-Origin' 'https://cool-napier.85-215-138-217.plesk.page';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';
        }
    }
  • For Apache:

    Add this in your .htaccess file:

    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "https://cool-napier.85-215-138-217.plesk.page"
        Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
        Header set Access-Control-Allow-Headers "Content-Type, Authorization"
    </IfModule>

Step 4: Test the Configuration

After making these changes, upload a new file through your application and verify that:

  1. The file has the correct permissions (0644).
  2. The file is accessible via its URL.
  3. The CORS headers are correctly set and no errors are shown in the console.

By following these steps, you should be able to ensure that files uploaded through your application have the correct permissions and are accessible from your frontend app without CORS issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment