PHP Class Jenssegers\Model\Model

Inheritance: implements ArrayAcces\ArrayAccess, implements Illuminate\Contracts\Support\Arrayable, implements Illuminate\Contracts\Support\Jsonable, implements JsonSerializabl\JsonSerializable
Show file Open project: jenssegers/model Class Usage Examples

Public Properties

Property Type Description
$snakeAttributes boolean Indicates whether attributes are snake cased on arrays.

Protected Properties

Property Type Description
$appends array The accessors to append to the model's array form.
$attributes array The model's attributes.
$casts array The attributes that should be casted to native types.
$fillable array The attributes that are mass assignable.
$guarded array The attributes that aren't mass assignable.
$hidden array The attributes that should be hidden for arrays.
$mutatorCache array The cache of the mutated attributes for each class.
$unguarded boolean Indicates if all mass assignment is enabled.
$visible array The attributes that should be visible in arrays.

Public Methods

Method Description
__callStatic ( string $method, array $parameters ) : mixed Handle dynamic static method calls into the method.
__construct ( array $attributes = [] ) : void Create a new Eloquent model instance.
__get ( string $key ) : mixed Dynamically retrieve attributes on the model.
__isset ( string $key ) : boolean Determine if an attribute exists on the model.
__set ( string $key, mixed $value ) : void Dynamically set attributes on the model.
__toString ( ) : string Convert the model to its string representation.
__unset ( string $key ) : void Unset an attribute on the model.
addHidden ( array | string | null $attributes = null ) : void Add hidden attributes for the model.
addVisible ( array | string | null $attributes = null ) : void Add visible attributes for the model.
attributesToArray ( ) : array Convert the model's attributes to an array.
cacheMutatedAttributes ( string $class ) : void Extract and cache all the mutated attributes of a class.
fill ( array $attributes ) Fill the model with an array of attributes.
fillable ( array $fillable ) Set the fillable attributes for the model.
forceFill ( array $attributes ) Fill the model with an array of attributes. Force mass assignment.
fromJson ( string $value, boolean $asObject = false ) : mixed Decode the given JSON back into an array or object.
getAttribute ( string $key ) : mixed Get an attribute from the model.
getAttributes ( ) : array Get all of the current attributes on the model.
getFillable ( ) : array Get the fillable attributes for the model.
getGuarded ( ) : array Get the guarded attributes for the model.
getHidden ( ) : array Get the hidden attributes for the model.
getMutatedAttributes ( ) : array Get the mutated attributes for a given instance.
getVisible ( ) : array Get the visible attributes for the model.
guard ( array $guarded ) Set the guarded attributes for the model.
hasGetMutator ( string $key ) : boolean Determine if a get mutator exists for an attribute.
hasSetMutator ( string $key ) : boolean Determine if a set mutator exists for an attribute.
hydrate ( array $items ) : array Create a collection of models from plain arrays.
isFillable ( string $key ) : boolean Determine if the given attribute may be mass assigned.
isGuarded ( string $key ) : boolean Determine if the given key is guarded.
isUnguarded ( ) : boolean Determine if current state is "unguarded".
jsonSerialize ( ) : array Convert the object into something JSON serializable.
newInstance ( array $attributes = [] ) : Model Create a new instance of the given model.
offsetExists ( mixed $offset ) : boolean Determine if the given attribute exists.
offsetGet ( mixed $offset ) : mixed Get the value for a given offset.
offsetSet ( mixed $offset, mixed $value ) : void Set the value for a given offset.
offsetUnset ( mixed $offset ) : void Unset the value for a given offset.
reguard ( ) : void Enable the mass assignment restrictions.
replicate ( array $except = null ) : Model Clone the model into a new, non-existing instance.
setAppends ( array $appends ) Set the accessors to append to model arrays.
setAttribute ( string $key, mixed $value ) Set a given attribute on the model.
setHidden ( array $hidden ) Set the hidden attributes for the model.
setVisible ( array $visible ) Set the visible attributes for the model.
toArray ( ) : array Convert the model instance to an array.
toJson ( integer $options ) : string Convert the model instance to JSON.
totallyGuarded ( ) : boolean Determine if the model is totally guarded.
unguard ( boolean $state = true ) : void Disable all mass assignable restrictions.
unguarded ( callable $callback ) : mixed Run the given callable while being unguarded.
withHidden ( array | string $attributes ) Make the given, typically hidden, attributes visible.

Protected Methods

Method Description
asJson ( mixed $value ) : string Encode the given value as JSON.
castAttribute ( string $key, mixed $value ) : mixed Cast an attribute to a native PHP type.
fillableFromArray ( array $attributes ) : array Get the fillable attributes of a given array.
getArrayableAppends ( ) : array Get all of the appendable values that are arrayable.
getArrayableAttributes ( ) : array Get an attribute array of all arrayable attributes.
getArrayableItems ( array $values ) : array Get an attribute array of all arrayable values.
getAttributeFromArray ( string $key ) : mixed Get an attribute from the $attributes array.
getAttributeValue ( string $key ) : mixed Get a plain attribute (not a relationship).
getCastType ( string $key ) : string Get the type of cast for a model attribute.
hasCast ( string $key ) : boolean Determine whether an attribute should be casted to a native type.
isJsonCastable ( string $key ) : boolean Determine whether a value is JSON castable for inbound manipulation.
mutateAttribute ( string $key, mixed $value ) : mixed Get the value of an attribute using its mutator.
mutateAttributeForArray ( string $key, mixed $value ) : mixed Get the value of an attribute using its mutator for array conversion.

Method Details

__callStatic() public static method

Handle dynamic static method calls into the method.
public static __callStatic ( string $method, array $parameters ) : mixed
$method string
$parameters array
return mixed

__construct() public method

Create a new Eloquent model instance.
public __construct ( array $attributes = [] ) : void
$attributes array
return void

__get() public method

Dynamically retrieve attributes on the model.
public __get ( string $key ) : mixed
$key string
return mixed

__isset() public method

Determine if an attribute exists on the model.
public __isset ( string $key ) : boolean
$key string
return boolean

__set() public method

Dynamically set attributes on the model.
public __set ( string $key, mixed $value ) : void
$key string
$value mixed
return void

__toString() public method

Convert the model to its string representation.
public __toString ( ) : string
return string

__unset() public method

Unset an attribute on the model.
public __unset ( string $key ) : void
$key string
return void

addHidden() public method

Add hidden attributes for the model.
public addHidden ( array | string | null $attributes = null ) : void
$attributes array | string | null
return void

addVisible() public method

Add visible attributes for the model.
public addVisible ( array | string | null $attributes = null ) : void
$attributes array | string | null
return void

asJson() protected method

Encode the given value as JSON.
protected asJson ( mixed $value ) : string
$value mixed
return string

attributesToArray() public method

Convert the model's attributes to an array.
public attributesToArray ( ) : array
return array

cacheMutatedAttributes() public static method

Extract and cache all the mutated attributes of a class.
public static cacheMutatedAttributes ( string $class ) : void
$class string
return void

castAttribute() protected method

Cast an attribute to a native PHP type.
protected castAttribute ( string $key, mixed $value ) : mixed
$key string
$value mixed
return mixed

fill() public method

Fill the model with an array of attributes.
public fill ( array $attributes )
$attributes array

fillable() public method

Set the fillable attributes for the model.
public fillable ( array $fillable )
$fillable array

fillableFromArray() protected method

Get the fillable attributes of a given array.
protected fillableFromArray ( array $attributes ) : array
$attributes array
return array

forceFill() public method

Fill the model with an array of attributes. Force mass assignment.
public forceFill ( array $attributes )
$attributes array

fromJson() public method

Decode the given JSON back into an array or object.
public fromJson ( string $value, boolean $asObject = false ) : mixed
$value string
$asObject boolean
return mixed

getArrayableAppends() protected method

Get all of the appendable values that are arrayable.
protected getArrayableAppends ( ) : array
return array

getArrayableAttributes() protected method

Get an attribute array of all arrayable attributes.
protected getArrayableAttributes ( ) : array
return array

getArrayableItems() protected method

Get an attribute array of all arrayable values.
protected getArrayableItems ( array $values ) : array
$values array
return array

getAttribute() public method

Get an attribute from the model.
public getAttribute ( string $key ) : mixed
$key string
return mixed

getAttributeFromArray() protected method

Get an attribute from the $attributes array.
protected getAttributeFromArray ( string $key ) : mixed
$key string
return mixed

getAttributeValue() protected method

Get a plain attribute (not a relationship).
protected getAttributeValue ( string $key ) : mixed
$key string
return mixed

getAttributes() public method

Get all of the current attributes on the model.
public getAttributes ( ) : array
return array

getCastType() protected method

Get the type of cast for a model attribute.
protected getCastType ( string $key ) : string
$key string
return string

getFillable() public method

Get the fillable attributes for the model.
public getFillable ( ) : array
return array

getGuarded() public method

Get the guarded attributes for the model.
public getGuarded ( ) : array
return array

getHidden() public method

Get the hidden attributes for the model.
public getHidden ( ) : array
return array

getMutatedAttributes() public method

Get the mutated attributes for a given instance.
public getMutatedAttributes ( ) : array
return array

getVisible() public method

Get the visible attributes for the model.
public getVisible ( ) : array
return array

guard() public method

Set the guarded attributes for the model.
public guard ( array $guarded )
$guarded array

hasCast() protected method

Determine whether an attribute should be casted to a native type.
protected hasCast ( string $key ) : boolean
$key string
return boolean

hasGetMutator() public method

Determine if a get mutator exists for an attribute.
public hasGetMutator ( string $key ) : boolean
$key string
return boolean

hasSetMutator() public method

Determine if a set mutator exists for an attribute.
public hasSetMutator ( string $key ) : boolean
$key string
return boolean

hydrate() public static method

Create a collection of models from plain arrays.
public static hydrate ( array $items ) : array
$items array
return array

isFillable() public method

Determine if the given attribute may be mass assigned.
public isFillable ( string $key ) : boolean
$key string
return boolean

isGuarded() public method

Determine if the given key is guarded.
public isGuarded ( string $key ) : boolean
$key string
return boolean

isJsonCastable() protected method

Determine whether a value is JSON castable for inbound manipulation.
protected isJsonCastable ( string $key ) : boolean
$key string
return boolean

isUnguarded() public static method

Determine if current state is "unguarded".
public static isUnguarded ( ) : boolean
return boolean

jsonSerialize() public method

Convert the object into something JSON serializable.
public jsonSerialize ( ) : array
return array

mutateAttribute() protected method

Get the value of an attribute using its mutator.
protected mutateAttribute ( string $key, mixed $value ) : mixed
$key string
$value mixed
return mixed

mutateAttributeForArray() protected method

Get the value of an attribute using its mutator for array conversion.
protected mutateAttributeForArray ( string $key, mixed $value ) : mixed
$key string
$value mixed
return mixed

newInstance() public method

Create a new instance of the given model.
public newInstance ( array $attributes = [] ) : Model
$attributes array
return Model

offsetExists() public method

Determine if the given attribute exists.
public offsetExists ( mixed $offset ) : boolean
$offset mixed
return boolean

offsetGet() public method

Get the value for a given offset.
public offsetGet ( mixed $offset ) : mixed
$offset mixed
return mixed

offsetSet() public method

Set the value for a given offset.
public offsetSet ( mixed $offset, mixed $value ) : void
$offset mixed
$value mixed
return void

offsetUnset() public method

Unset the value for a given offset.
public offsetUnset ( mixed $offset ) : void
$offset mixed
return void

reguard() public static method

Enable the mass assignment restrictions.
public static reguard ( ) : void
return void

replicate() public method

Clone the model into a new, non-existing instance.
public replicate ( array $except = null ) : Model
$except array
return Model

setAppends() public method

Set the accessors to append to model arrays.
public setAppends ( array $appends )
$appends array

setAttribute() public method

Set a given attribute on the model.
public setAttribute ( string $key, mixed $value )
$key string
$value mixed

setHidden() public method

Set the hidden attributes for the model.
public setHidden ( array $hidden )
$hidden array

setVisible() public method

Set the visible attributes for the model.
public setVisible ( array $visible )
$visible array

toArray() public method

Convert the model instance to an array.
public toArray ( ) : array
return array

toJson() public method

Convert the model instance to JSON.
public toJson ( integer $options ) : string
$options integer
return string

totallyGuarded() public method

Determine if the model is totally guarded.
public totallyGuarded ( ) : boolean
return boolean

unguard() public static method

Disable all mass assignable restrictions.
public static unguard ( boolean $state = true ) : void
$state boolean
return void

unguarded() public static method

Run the given callable while being unguarded.
public static unguarded ( callable $callback ) : mixed
$callback callable
return mixed

withHidden() public method

Make the given, typically hidden, attributes visible.
public withHidden ( array | string $attributes )
$attributes array | string

Property Details

$appends protected property

The accessors to append to the model's array form.
protected array $appends
return array

$attributes protected property

The model's attributes.
protected array $attributes
return array

$casts protected property

The attributes that should be casted to native types.
protected array $casts
return array

$fillable protected property

The attributes that are mass assignable.
protected array $fillable
return array

$guarded protected property

The attributes that aren't mass assignable.
protected array $guarded
return array

$hidden protected property

The attributes that should be hidden for arrays.
protected array $hidden
return array

$mutatorCache protected static property

The cache of the mutated attributes for each class.
protected static array $mutatorCache
return array

$snakeAttributes public static property

Indicates whether attributes are snake cased on arrays.
public static bool $snakeAttributes
return boolean

$unguarded protected static property

Indicates if all mass assignment is enabled.
protected static bool $unguarded
return boolean

$visible protected property

The attributes that should be visible in arrays.
protected array $visible
return array