primary key in laravel code example

Example 1: laravel remove foreign key

$table->dropForeign('posts_user_id_foreign');

Example 2: laravel make model with migration 5.8

php artisan make:model Settings --migration

Example 3: laravel longblob migration

DB::statement("ALTER TABLE <table name> ADD <column name> MEDIUMBLOB");

Example 4: by default null eloquent user data in relationship in laravel 8

# simple handle in blade file 
{{ $post->author->name or 'No author' }}

# Model action 
public function author()
{
    return $this->belongsTo('App\Author')->withDefault();
}

public function author()
{
    return $this->belongsTo('App\Author')->withDefault([
        'name' => 'Guest Author',
    ]);
}

Tags:

Php Example