BelongsOrMorphsToMany

 trait Winter\Storm\Database\Relations\Concerns\BelongsOrMorphsToMany

Properties

public $countMode : bool

This relation object is a 'count' helper.

public $orphanMode : bool

When a join is not used, don't select aliased columns.

Methods

public __construct (Winter\Storm\Database\Builder $query, Winter\Storm\Database\Model $parent, string $table, string $foreignPivotKey, string $relatedPivotKey, $parentKey, $relatedKey, string $relationName = null) : void

Create a new belongs to many relationship instance.

Parameters
Property Description
$query
Winter\Storm\Database\Builder
$parent
Winter\Storm\Database\Model
$table
string
$foreignPivotKey
string
$relatedPivotKey
string
$parentKey
mixed
$relatedKey
mixed
$relationName
string
Returns
void

public add (Illuminate\Database\Eloquent\Model $model, $sessionKey = null, array $pivotData = [])

Adds a model to this relationship type.

Parameters
Property Description
$model
Illuminate\Database\Eloquent\Model
$sessionKey
mixed
$pivotData
array
Returns
mixed

public allRelatedIds (string $sessionKey = null) : Illuminate\Support\Collection

Get all of the IDs for the related models, with deferred binding support

Parameters
Property Description
$sessionKey
string
Returns
Illuminate\Support\Collection

public attach (mixed $id, array $attributes = [], boolean $touch = true)

Override attach() method of BelongToMany relation.

This is necessary in order to fire 'model.relation.beforeAttach', 'model.relation.afterAttach' events

Parameters
Property Description
$id
mixed
$attributes
array
$touch
boolean
Returns
mixed

public create (array $attributes = [], array $pivotData = [], $sessionKey = null)

Create a new instance of this related model with deferred binding support.

Parameters
Property Description
$attributes
array
$pivotData
array
$sessionKey
mixed
Returns
mixed

public detach (Collection | Model | array | null $ids = null, boolean $touch = true) : int | void

Override detach() method of BelongToMany relation.

This is necessary in order to fire 'model.relation.beforeDetach', 'model.relation.afterDetach' events

Parameters
Property Description
$ids
Collection | Model | array | null
$touch
boolean
Returns
int | void

public getForeignKey () : string

Get the fully qualified foreign key for the relation.

Returns
string

public getOtherKey () : string

Get the fully qualified "other key" for the relation.

Returns
string

public getRelatedIds ($sessionKey = null)

Parameters
Property Description
$sessionKey
mixed
Returns
mixed

public getSimpleValue ()

Helper for getting this relationship simple value, generally useful with form values.

Returns
mixed

public newPivot (array $attributes = [], boolean $exists = false) : Illuminate\Database\Eloquent\Relations\Pivot

Create a new pivot model instance.

Parameters
Property Description
$attributes
array
$exists
boolean
Returns
Illuminate\Database\Eloquent\Relations\Pivot

public paginate (integer $perPage = 15, int $currentPage = null, array $columns = ["*"], string $pageName = "page") : Illuminate\Contracts\Pagination\LengthAwarePaginator

Get a paginator for the "select" statement. Complies with Winter Storm.

Parameters
Property Description
$perPage
integer
$currentPage
int
$columns
array
$pageName
string
Returns
Illuminate\Contracts\Pagination\LengthAwarePaginator

public remove (Illuminate\Database\Eloquent\Model $model, $sessionKey = null)

Removes a model from this relationship type.

Parameters
Property Description
$model
Illuminate\Database\Eloquent\Model
$sessionKey
mixed
Returns
mixed

public save (Illuminate\Database\Eloquent\Model $model, array $pivotData = [], $sessionKey = null)

Save the supplied related model with deferred binding support.

Parameters
Property Description
$model
Illuminate\Database\Eloquent\Model
$pivotData
array
$sessionKey
mixed
Returns
mixed

public setSimpleValue ($value)

Helper for setting this relationship using various expected values. For example, $model->relation = $value;

Parameters
Property Description
$value
mixed
Returns
mixed

public sync (array $ids, boolean $detaching = true) : array

Override sync() method of BelongToMany relation in order to flush the query cache.

Parameters
Property Description
$ids
array
$detaching
boolean
Returns
array

protected shouldSelect (array $columns = ["*"]) : array | string

Get the select columns for the relation query.

Parameters
Property Description
$columns
array
Returns
array | string
Copyright © 2024 Winter CMS