本文整理匯總了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');
}