本文整理汇总了PHP中Laravel\Spark\Spark::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Spark::model方法的具体用法?PHP Spark::model怎么用?PHP Spark::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Laravel\Spark\Spark
的用法示例。
在下文中一共展示了Spark::model方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Create a new team for the given user and data.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param array $data
* @return \Laravel\Spark\Teams\Team
*/
public function create($user, array $data)
{
$class = Spark::model('teams', Team::class);
$team = new $class(['name' => $data['name']]);
$team->owner_id = $user->id;
$team->save();
$team = $user->teams()->attach($team, ['role' => 'owner']);
return $team;
}
示例2: team
/**
* Get the team that owns the invitation.
*/
public function team()
{
return $this->belongsTo(Spark::model('teams', Team::class), 'team_id');
}
示例3: teams
/**
* Get all of the teams that the user belongs to.
*/
public function teams()
{
return $this->belongsToMany(Spark::model('teams', Team::class), 'user_teams', 'user_id', 'team_id')->withPivot(['role'])->orderBy('name', 'asc');
}