Hello. I can't deal with the package, and I need help.
My migration.
database/migrations/2017_10_31_072845_create_images_table.php
...
/**
* @return array
*/
protected function attributes(): array
{
return [
[
'type' => 'varchar',
'name' => 'MIME type',
'slug' => 'mime',
'entities' => [\App\Models\Image::class],
'group' => 'metadata',
],
[
'type' => 'integer',
'name' => 'Image width',
'slug' => 'width',
'entities' => [\App\Models\Image::class],
'group' => 'metadata',
],
[
'type' => 'integer',
'name' => 'Image height',
'slug' => 'height',
'entities' => [\App\Models\Image::class],
'group' => 'metadata',
],
[
'type' => 'integer',
'name' => 'Image size',
'slug' => 'size',
'entities' => [\App\Models\Image::class],
'group' => 'metadata',
]
];
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('images', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('bucket_id');
$table->integer('user_id');
$table->boolean('processed')->default(0);
$table->timestamps();
$table->unique(['name']);
});
foreach ($this->attributes() as $attribute) {
app('rinvex.attributes.attribute')
->create($attribute);
}
}
...
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\app('rinvex.attributes.entities')->push(Image::class);
}
namespace App\Models;
use Rinvex\Attributes\Traits\Attributable;
class Image extends Model
{
use Attributable;
protected $with = ['eav'];
...
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$image = Image::query()->first();
if (!$image) {
$image = new Image();
$image->name = Image::generateName(1, 'png');
$image->bucket_id = 1;
$image->user_id = 1;
$image->save();
}
}