Image

laravel

Bugs

Manage some basics bugs

2 min read
Last update: November 28, 2021

Permission denied

sudo chown -R $USER:www-data * ; sudo chmod -R ug+rwx storage bootstrap/cache

spatie/laravel-medialibrary media not created

If spatie/laravel-medialibrary no create any file in media directory.

Assure than public/storage is not track by git.

rm public/storage
php artisan storage:link

API Limit requests

For Laravel 7+

app/Providers/RouteServiceProvider.php
<?php

class RouteServiceProvider extends ServiceProvider
{
    /**
     * Configure the rate limiters for the application.
     *
     * @return void
     */
    protected function configureRateLimiting()
    {
        RateLimiter::for('api', function (Request $request) {
            return Limit::perMinute(2000)->by(optional($request->user())->id ?: $request->ip()); // Update Limit::perMinute(60) to Limit::perMinute(2000)
        });
    }
}

For old version

app/Http/Kernel.php
class Kernel extends HttpKernel
{
    // ...

    /**
     * The application's route middleware groups.
     *
     * @var array
     */

    protected $middlewareGroups = [
        'web' => [
            // ...
        ],

        'api' => [
            // 'throttle:60,1', <- Remove this line
            'bindings',
        ],
    ];
    // ...
}

Proxy

To enable https for application.

app/Http/Middleware/TrustProxies.php
<?php

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array|string|null
     */
    protected $proxies = '*';

    /**
     * The headers that should be used to detect proxies.
     *
     * @var int
     */
    protected $headers = Request::HEADER_X_FORWARDED_ALL;
}