Answers for "primary key in laravel"

PHP
1

laravel model string primary key

class UserVerification extends Model
{
    protected $primaryKey = 'your_key_name'; // or null

    public $incrementing = false;

    // In Laravel 6.0+ make sure to also set $keyType
    protected $keyType = 'string';
}
Posted by: Guest on December-14-2020
3

laravel remove foreign key

$table->dropForeign('posts_user_id_foreign');
Posted by: Guest on April-22-2020
1

laravel make model with migration 5.8

php artisan make:model Settings --migration
Posted by: Guest on December-09-2020
0

laravel longblob migration

DB::statement("ALTER TABLE <table name> ADD <column name> MEDIUMBLOB");
Posted by: Guest on September-08-2020
0

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',
    ]);
}
Posted by: Guest on February-04-2021

Browse Popular Code Answers by Language