ImportModel
Model used for importing data
abstract class Backend\Models\ImportModel
extends Model
Extends
Class | Description |
---|---|
Model
|
Traits
Trait | Description |
---|---|
Validation
|
Properties
public
$attachOne
:
mixed
= {"import_file":{"0":{},"public":false}}
Relations
protected
$guarded
:
array
= []
The attributes that aren't mass assignable.
protected
$resultStats
:
array
= {"updated":0,"created":0,"errors":[],"warnings":[],"skipped":[]}
Import statistics store.
inherited
protected
$validationDefaultAttrNames
:
array
= []
Default custom attribute names.
inherited protected $validationErrors : Illuminate\Support\MessageBag
The message bag instance containing validation error messages
Methods
public getFormatEncodingOptions () : array
Returns all available encodings values from the localization config
public
getImportFilePath ($sessionKey = null
)
: string
Returns an attached imported file local path, if available.
Property | Type | Description |
---|---|---|
$sessionKey | mixed |
mixed
|
public getResultStats ()
public
import ($matches, array $options = []
)
Import data based on column names matching header indexes in the CSV.
The $matches array should be in the format of:
[ 0 => [db_name1, db_name2], 1 => [db_name3], ... ]
The key (0, 1) is the column index in the CSV and the value is another array of target database column names.
Property | Type | Description |
---|---|---|
$matches | mixed |
mixed
|
$options | array |
array
|
public
importData ($results, $sessionKey = null
)
Called when data is being imported.
The $results array should be in the format of:
[ 'db_name1' => 'Some value', 'db_name2' => 'Another value' ], [...]
Property | Type | Description |
---|---|---|
$results | mixed |
mixed
|
$sessionKey | mixed |
mixed
|
protected
decodeArrayValue ($value, string $delimeter = "|"
)
: array
Explodes a string using pipes (|) to a single dimension array
Property | Type | Description |
---|---|---|
$value | mixed |
mixed
|
$delimeter | string |
string
|
protected logCreated ()
protected logError ($rowIndex, $message)
Property | Type | Description |
---|---|---|
$rowIndex | mixed |
mixed
|
$message | mixed |
mixed
|
protected logSkipped ($rowIndex, $message)
Property | Type | Description |
---|---|---|
$rowIndex | mixed |
mixed
|
$message | mixed |
mixed
|
protected logUpdated ()
protected logWarning ($rowIndex, $message)
Property | Type | Description |
---|---|---|
$rowIndex | mixed |
mixed
|
$message | mixed |
mixed
|
protected processImportData ($filePath, $matches, $options) : array
Converts column index to database column map to an array containing database column names and values pulled from the CSV file. Eg:
[0 => [first_name], 1 => [last_name]]
Will return:
[first_name => Joe, last_name => Blogs], [first_name => Harry, last_name => Potter], [...]
Property | Type | Description |
---|---|---|
$filePath | mixed |
mixed
|
$matches | mixed |
mixed
|
$options | mixed |
mixed
|
protected processImportRow ($rowData, $matches) : array
Converts a single row of CSV data to the column map.
Property | Type | Description |
---|---|---|
$rowData | mixed |
mixed
|
$matches | mixed |
mixed
|
inherited public static bootValidation () : void
Boot the validation trait for this model.
inherited public errors () : Illuminate\Support\MessageBag
Get validation error message collection for the Model
inherited
public
forceSave ($options = null
, $sessionKey = null
)
: bool
Force save the model even if validation fails.
Property | Type | Description |
---|---|---|
$options | mixed |
mixed
|
$sessionKey | mixed |
mixed
|
inherited
public
isAttributeRequired (string $attribute, boolean $checkDependencies = true
)
: bool
Determines if an attribute is required based on the validation rules.
Property | Type | Description |
---|---|---|
$attribute | string |
string
|
$checkDependencies | boolean |
boolean
Checks the attribute dependencies (for required_if & required_with rules). Note that it will only be checked up to the next level, if another dependent rule is found then it will just assume the field is required |
inherited public setValidationAttributeName (string $attr, string $name) : void
Programatically sets the validation attribute names, will take lower priority
to model defined attribute names found in $attributeNames
.
Property | Type | Description |
---|---|---|
$attr | string |
string
|
$name | string |
string
|
inherited public setValidationAttributeNames (array $attributeNames) : void
Programatically sets multiple validation attribute names.
Property | Type | Description |
---|---|---|
$attributeNames | array |
array
|
inherited
public
validate ($rules = null
, $customMessages = null
, $attributeNames = null
)
: bool
Validate the model instance
Property | Type | Description |
---|---|---|
$rules | mixed |
mixed
|
$customMessages | mixed |
mixed
|
$attributeNames | mixed |
mixed
|
inherited public static validated (Closure | string $callback) : void
Create a new native event for handling afterValidate().
Property | Type | Description |
---|---|---|
$callback | Closure | string |
Closure | string
|
inherited public static validating (Closure | string $callback) : void
Create a new native event for handling beforeValidate().
Property | Type | Description |
---|---|---|
$callback | Closure | string |
Closure | string
|
inherited protected getRelationValidationValue ($relationName)
Attachments validate differently to their simple values.
Property | Type | Description |
---|---|---|
$relationName | mixed |
mixed
|
inherited protected getValidationAttributes () : array
Returns the model data used for validation.
inherited
protected
static
makeValidator ($data, $rules, $customMessages, $attributeNames, $connection = null
)
: Illuminate\Contracts\Validation\Validator
Instantiates the validator used by the validation process, depending if the class is being used inside or outside of Laravel. Optional connection string to make the validator use a different database connection than the default connection.
Property | Type | Description |
---|---|---|
$data | mixed |
mixed
|
$rules | mixed |
mixed
|
$customMessages | mixed |
mixed
|
$attributeNames | mixed |
mixed
|
$connection | mixed |
mixed
|
inherited protected processRuleFieldNames (array $rules) : array
Processes field names in a rule array.
Converts any field names using array notation (ie. field[child]
) into dot notation (ie. field.child
)
Property | Type | Description |
---|---|---|
$rules | array |
array
Rules array |
inherited protected processValidationRules ($rules)
Process rules
Property | Type | Description |
---|---|---|
$rules | mixed |
mixed
|
inherited protected processValidationUniqueRule (string $definition, string $fieldName) : string
Rebuilds the unique validation rule to force for the existing ID
Property | Type | Description |
---|---|---|
$definition | string |
string
|
$fieldName | string |
string
|