Laravel mnoho k mnoha vztahům s kontingenční tabulkou

Příklady kódu

7
0

jeden až mnoho laravel

For example, a blog post may have an infinite number of comments. And a single
comment belongs to only a single post  

class Post extends Model
{
    public function comments()
    {
        return $this->hasMany('App\Models\Comment');
    }
}

class Comment extends Model
{
    public function post()
    {
        return $this->belongsTo('App\Models\Post');
    }
}
5
0

Laravel oddělit

// Detach a single role from the user...
$user->roles()->detach($roleId);

// Detach all roles from the user...
$user->roles()->detach();
1
0

laravel mnoho k mnoha vztahům s kontingenční tabulkou

$user = User::find(1); //any user we want to find 
$user->trophies()->attach($idOfTrophy); 
//pass id or array of a Trophy ids 
//suppose admin has selected the trophy from a form and trophy id
// is in $request object, then.
$trophyId = $request->trophy_id;
$user->trophies()->attach($trophyId); //record is created in DB.
attach and syncWithoutDetaching both does same job
0
0

laravel mnoho k mnoha aktualizovat všechny pivot

$user->customviews()
    ->newPivotStatement()
    ->where('user_id', '=', $user->id)
    ->update(array('default' => 0));
0
0

laravel mnoho k mnoha vztahům s kontingenční tabulkou

$user = User::find(1); //any user we want to find $user->trophies()->attach($idOfTrophy); //pass id or array of a Trophy ids //suppose admin has selected the trophy from a form and trophy id// is in $request object, then.$trophyId = $request->trophy_id;$user->trophies()->attach($trophyId); //record is created in DB.attach and syncWithoutDetaching both does same job

V jiných jazycích

Tato stránka je v jiných jazycích

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................