feat: scene update
This commit is contained in:
@@ -77,9 +77,10 @@ public function store(Request $request)
|
|||||||
'theme_id' => 'nullable|exists:themes,id',
|
'theme_id' => 'nullable|exists:themes,id',
|
||||||
'order' => 'nullable|integer',
|
'order' => 'nullable|integer',
|
||||||
'is_active' => 'nullable|boolean',
|
'is_active' => 'nullable|boolean',
|
||||||
|
'is_premium' => 'nullable|boolean',
|
||||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||||
'video' => 'nullable|mimes:mp4,mov,webm|max:512000',
|
'video' => 'nullable|file|extensions:mp4,mov,webm,mkv,avi,m4v,3gp|max:512000',
|
||||||
'sound' => 'nullable|mimes:mp3,wav,ogg,flac|max:51200',
|
'sound' => 'nullable|file|extensions:mp3,wav,ogg,flac,aac,m4a,opus,mpga,wma|max:51200',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$scene = Scene::create([
|
$scene = Scene::create([
|
||||||
@@ -87,6 +88,7 @@ public function store(Request $request)
|
|||||||
'theme_id' => $data['theme_id'] ?? null,
|
'theme_id' => $data['theme_id'] ?? null,
|
||||||
'order' => $data['order'] ?? 0,
|
'order' => $data['order'] ?? 0,
|
||||||
'is_active' => $data['is_active'] ?? true,
|
'is_active' => $data['is_active'] ?? true,
|
||||||
|
'is_premium' => $data['is_premium'] ?? false,
|
||||||
'image_path' => $request->hasFile('image') ? $request->file('image')->store('scenes/images', 'public') : null,
|
'image_path' => $request->hasFile('image') ? $request->file('image')->store('scenes/images', 'public') : null,
|
||||||
'video_path' => $request->hasFile('video') ? $request->file('video')->store('scenes/videos', 'public') : null,
|
'video_path' => $request->hasFile('video') ? $request->file('video')->store('scenes/videos', 'public') : null,
|
||||||
'sound_path' => $request->hasFile('sound') ? $request->file('sound')->store('scenes/sounds', 'public') : null,
|
'sound_path' => $request->hasFile('sound') ? $request->file('sound')->store('scenes/sounds', 'public') : null,
|
||||||
@@ -108,9 +110,10 @@ public function update(Request $request, $id)
|
|||||||
'theme_id' => 'nullable|exists:themes,id',
|
'theme_id' => 'nullable|exists:themes,id',
|
||||||
'order' => 'nullable|integer',
|
'order' => 'nullable|integer',
|
||||||
'is_active' => 'nullable|boolean',
|
'is_active' => 'nullable|boolean',
|
||||||
|
'is_premium' => 'nullable|boolean',
|
||||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||||
'video' => 'nullable|mimes:mp4,mov,webm|max:512000',
|
'video' => 'nullable|file|extensions:mp4,mov,webm,mkv,avi,m4v,3gp|max:512000',
|
||||||
'sound' => 'nullable|mimes:mp3,wav,ogg,flac|max:51200',
|
'sound' => 'nullable|file|extensions:mp3,wav,ogg,flac,aac,m4a,opus,mpga,wma|max:51200',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (array_key_exists('name', $data)) {
|
if (array_key_exists('name', $data)) {
|
||||||
@@ -125,6 +128,9 @@ public function update(Request $request, $id)
|
|||||||
if (array_key_exists('is_active', $data)) {
|
if (array_key_exists('is_active', $data)) {
|
||||||
$scene->is_active = $data['is_active'];
|
$scene->is_active = $data['is_active'];
|
||||||
}
|
}
|
||||||
|
if (array_key_exists('is_premium', $data)) {
|
||||||
|
$scene->is_premium = $data['is_premium'];
|
||||||
|
}
|
||||||
|
|
||||||
foreach (['image' => 'scenes/images', 'video' => 'scenes/videos', 'sound' => 'scenes/sounds'] as $field => $folder) {
|
foreach (['image' => 'scenes/images', 'video' => 'scenes/videos', 'sound' => 'scenes/sounds'] as $field => $folder) {
|
||||||
if ($request->hasFile($field)) {
|
if ($request->hasFile($field)) {
|
||||||
|
|||||||
@@ -7,10 +7,11 @@
|
|||||||
|
|
||||||
class Scene extends Model
|
class Scene extends Model
|
||||||
{
|
{
|
||||||
protected $fillable = ['theme_id', 'name', 'image_path', 'video_path', 'sound_path', 'order', 'is_active'];
|
protected $fillable = ['theme_id', 'name', 'image_path', 'video_path', 'sound_path', 'order', 'is_active', 'is_premium'];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'is_active' => 'boolean',
|
'is_active' => 'boolean',
|
||||||
|
'is_premium' => 'boolean',
|
||||||
'order' => 'integer',
|
'order' => 'integer',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('scenes', function (Blueprint $table) {
|
||||||
|
$table->boolean('is_premium')->default(false)->after('is_active');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('scenes', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('is_premium');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user