Laravel Tips

Set up file permissions for Laravel project

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

Composite unique field validation

'term'  => 'unique:terms,term,NULL,id,taxonomy,category'

This rule says that term should be unique on the terms table but only where the taxonomy is equal to “category”.

Get route object in validation

// record/{record}
// Getting object
$this->route('record');

Load Blade assets with HTTPS protocol

Helper function asset loads resources through HTTP protocol and if your website is using HTTPS protocol, you will get “Mixed content” warnings.

To solve this, write the following into your AppServiceProvider boot() function:

use Illuminate\Support\Facades\URL;

public function boot()
{
    if (config('app.env') === 'production') {
        URL::forceScheme('https');
    }
}