Skip to content

Commit cd45c2c

Browse files
committed
feat: add banner migrations and models
1 parent d20730c commit cd45c2c

8 files changed

Lines changed: 261 additions & 0 deletions
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
public function up(): void
9+
{
10+
Schema::create('cms_banner_positions', function (Blueprint $table) {
11+
$table->id();
12+
13+
if (config('eclipse-cms.tenancy.enabled')) {
14+
$tenantClass = config('eclipse-cms.tenancy.model');
15+
/** @var \Illuminate\Database\Eloquent\Model $tenant */
16+
$tenant = new $tenantClass;
17+
$table->foreignId(config('eclipse-cms.tenancy.foreign_key'))
18+
->constrained($tenant->getTable(), $tenant->getKeyName())
19+
->cascadeOnUpdate()
20+
->cascadeOnDelete();
21+
}
22+
23+
$table->string('name');
24+
$table->string('code', 20)->nullable();
25+
$table->timestamps();
26+
$table->softDeletes();
27+
});
28+
}
29+
30+
public function down(): void
31+
{
32+
Schema::dropIfExists('cms_banner_positions');
33+
}
34+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
public function up(): void
9+
{
10+
Schema::create('cms_banner_image_types', function (Blueprint $table) {
11+
$table->id();
12+
$table->foreignId('position_id');
13+
$table->string('name');
14+
$table->string('code')->nullable();
15+
$table->smallInteger('image_width')->nullable();
16+
$table->smallInteger('image_height')->nullable();
17+
$table->boolean('is_hidpi');
18+
});
19+
}
20+
21+
public function down(): void
22+
{
23+
Schema::dropIfExists('cms_banner_image_types');
24+
}
25+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
public function up(): void
9+
{
10+
Schema::create('cms_banners', function (Blueprint $table) {
11+
$table->id();
12+
$table->foreignId('position_id')
13+
->constrained('cms_banner_positions', 'id')
14+
->cascadeOnUpdate()
15+
->cascadeOnDelete();
16+
$table->string('name');
17+
$table->string('link')->nullable();
18+
$table->boolean('is_active')->default(false);
19+
$table->boolean('new_tab')->default(false);
20+
$table->unsignedTinyInteger('sort')->default(0);
21+
$table->timestamps();
22+
$table->softDeletes();
23+
});
24+
}
25+
26+
public function down(): void
27+
{
28+
Schema::dropIfExists('cms_banners');
29+
}
30+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
public function up(): void
9+
{
10+
Schema::create('cms_banner_images', function (Blueprint $table) {
11+
$table->id();
12+
$table->foreignId('banner_id')
13+
->constrained('cms_banners', 'id')
14+
->cascadeOnUpdate()
15+
->cascadeOnDelete();
16+
$table->foreignId('type_id')
17+
->constrained('cms_banner_image_types', 'id')
18+
->cascadeOnUpdate()
19+
->cascadeOnDelete();
20+
$table->string('file');
21+
$table->boolean('is_hidpi');
22+
$table->smallInteger('image_width');
23+
$table->smallInteger('image_height');
24+
});
25+
}
26+
27+
public function down(): void
28+
{
29+
Schema::dropIfExists('cms_banner_images');
30+
}
31+
};

src/Models/Banner.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Eclipse\Cms\Models;
4+
5+
use Eclipse\Cms\Models\Banner\Position;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
use Illuminate\Database\Eloquent\SoftDeletes;
9+
10+
class Banner extends Model
11+
{
12+
use SoftDeletes;
13+
14+
protected $table = 'cms_banners';
15+
16+
protected $fillable = [
17+
'position_id',
18+
];
19+
20+
public function position(): BelongsTo
21+
{
22+
return $this->belongsTo(Position::class, 'position_id');
23+
}
24+
}

src/Models/Banner/Image.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Eclipse\Cms\Models\Banner;
4+
5+
use Eclipse\Cms\Models\Banner;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
9+
/**
10+
* @property int $id Image ID
11+
* @property int $banner_id Banner ID
12+
* @property int $type_id Banner image type ID
13+
* @property string $file Image file path
14+
* @property bool $is_hidpi Whether the image is hidpi (x2)
15+
* @property int $image_width Image width
16+
* @property int $image_height Image height
17+
*/
18+
class Image extends Model
19+
{
20+
public $timestamps = false;
21+
22+
protected $table = 'cms_banner_images';
23+
24+
protected $fillable = [
25+
'banner_id',
26+
'type_id',
27+
'file',
28+
'is_hidpi',
29+
'image_width',
30+
'image_height',
31+
];
32+
33+
public function banner(): BelongsTo
34+
{
35+
return $this->belongsTo(Banner::class, 'banner_id');
36+
}
37+
38+
public function type(): BelongsTo
39+
{
40+
return $this->belongsTo(ImageType::class, 'type_id');
41+
}
42+
43+
protected function casts(): array
44+
{
45+
return [
46+
'is_hidpi' => 'boolean',
47+
];
48+
}
49+
}

src/Models/Banner/ImageType.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Eclipse\Cms\Models\Banner;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7+
8+
/**
9+
* Type of banner image
10+
*
11+
* @property int $id Type ID
12+
* @property int $position_id Position ID
13+
* @property string $name Type name (e.g. Desktop, Mobile)
14+
* @property string|null $code Optional type code (for programmatic use)
15+
* @property int|null $image_width Optional image width (for upload validation)
16+
* @property int|null $image_height Optional image height (for upload validation)
17+
* @property bool $is_hidpi Whether to require hidpi images (x2) when uploading
18+
*/
19+
class ImageType extends Model
20+
{
21+
public $timestamps = false;
22+
23+
protected $table = 'cms_banner_image_types';
24+
25+
protected $fillable = [
26+
'name',
27+
'position_id',
28+
'code',
29+
'image_width',
30+
'image_height',
31+
'is_hidpi',
32+
];
33+
34+
public function position(): BelongsTo
35+
{
36+
return $this->belongsTo(Position::class, 'position_id');
37+
}
38+
39+
protected function casts(): array
40+
{
41+
return [
42+
'is_hidpi' => 'boolean',
43+
];
44+
}
45+
}

src/Models/Banner/Position.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Eclipse\Cms\Models\Banner;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\SoftDeletes;
7+
8+
/**
9+
* @property int $id Position ID
10+
* @property string $name Position name
11+
* @property string|null code Optional position code (for programmatic use)
12+
*/
13+
class Position extends Model
14+
{
15+
use SoftDeletes;
16+
17+
protected $table = 'cms_banner_positions';
18+
19+
protected $fillable = [
20+
'name',
21+
'code',
22+
];
23+
}

0 commit comments

Comments
 (0)