database seeder Flashcards

1
Q

inserting with db::seed

A

use Illustrate/…/DB
DB::table(‘tblname’)->insert([
..])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Massive input in db::seed

A

User::factory()->count(10)->create();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

One to One realtionship

A
Belong to method
Phone ->foreign key= User_id to User-> primary key= ID
IN Phone class-
public function user(){
        return $this->belongsTo(User::class);
    }
e.g 
Route::get('/connect',function (){
         $phone = Phone::find(2);
         $result = $phone->user;
         return $result;
});
         Or User to Phone (useer has many phones but you wanna need one) public function phone(){
    return $this->hasOne(Phone::class);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

One to Many

A

User to Phone (useer has many phones )
public function phone(){
return $this->hasMany(Phone::class);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Many to Many

A
Many User have Many roles
create pivot table like
Note name must be alphabetical
role_user table(r is prior to u)
user_id< - > role_id

public function roles(){
return $this->BelongtoMany(Role::class,’pivotableName’);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly