I have a simple Laravel Eloquest Model with some fileable attributes and relations. This model is connected to DB, and worked good two months ago. After updating a table and adding a new column status, something become broken. Here is my model:
class Good extends Model
{
protected $table = 'product_goods';
public $incrementing = false;
protected $fillable = ['sku', 'status'];
/**
* @return BelongsTo
* @noinspection PhpUnused
*/
public function product() {
return $this->belongsTo(Product::class);
}
/**
* @return BelongsTo
* @noinspection PhpUnused
*/
public function color() {
return $this->belongsTo(Color::class);
}
/**
* @return BelongsToMany
*/
public function sizes() {
return $this->belongsToMany(Size::class, 'product_good_size');
}
/**
* @return BelongsTo
* @noinspection PhpUnused
*/
public function sizeStandard() {
return $this->belongsTo(SizeStandard::class);
}
/**
* @return MorphMany
* @noinspection PhpUnused
*/
public function files() {
return $this->morphMany(File::class, 'fileable')
->orderBy('show_priority');
}
/**
* @return HasMany
* @noinspection PhpUnused
*/
public function prices() {
return $this->hasMany(Price::class);
}
}
Then i'm trying to make() this model like this:
$goodData = [
'prices' => [
'RUB' => 788,
'UAH' => 499,
],
'color_id' => Color::first()->id,
'size_standard_id' => $sizeStandard->id,
'sizes' => $sizeIds,
'sku' => $faker->uuid,
'files' => [
['file' => UploadedFile::fake(),],
['file' => UploadedFile::fake(),],
['file' => UploadedFile::fake(),],
['file' => UploadedFile::fake(),],
],
];
$good = Good::make($goodData);
Then i got illegal attributes, which I dont want to see. I need only fillable attributes, but i see whole data, which is wrong.
App\Models\Product\Good^ {#1207
#table: "product_goods"
+incrementing: false
#fillable: array:2 [
0 => "sku"
1 => "status"
]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
#with: []
#withCount: []
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes: array:7 [
"prices" => array:2 [
"RUB" => 788
"UAH" => 499
]
"color_id" => "6922c4e9-462f-4ce8-8028-36116845f0ea"
"size_standard_id" => "5f367199-c28a-4dc7-a979-d46f019eb2ac"
"sizes" => array:6 [
0 => array:1 [
"id" => "275c9efd-f5b6-437c-b0f1-a05c278404bd"
]
1 => array:1 [
"id" => "3090beb1-7fd3-4f79-9977-1d78abf83d09"
]
2 => array:1 [
"id" => "3121d205-101e-4cf1-8130-1bd94a2c255d"
]
3 => array:1 [
"id" => "b903d4c0-d33d-4191-8fb5-9b625b06ef7f"
]
4 => array:1 [
"id" => "deddbd28-4e72-46bc-b317-8ab8a68c2ed7"
]
5 => array:1 [
"id" => "f4139b5a-b703-4cd0-a29a-44f66aae18fc"
]
]
"sku" => "62471d6b-04c6-3b88-a9af-2960f96b78a9"
"files" => array:4 [
0 => array:1 [
"file" => Illuminate\Http\Testing\FileFactory^ {#1162}
]
1 => array:1 [
"file" => Illuminate\Http\Testing\FileFactory^ {#1187}
]
2 => array:1 [
"file" => Illuminate\Http\Testing\FileFactory^ {#1164}
]
3 => array:1 [
"file" => Illuminate\Http\Testing\FileFactory^ {#1157}
]
]
"status" => "active"
]
#original: []
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [
0 => "*"
]
}
What do I do wrong?