fix: change music duration to int #3

Merged
Amirmahdi merged 2 commits from feature/save into main 2026-05-22 21:54:32 +00:00
3 changed files with 35 additions and 7 deletions
Showing only changes of commit e314f95656 - Show all commits
+2 -2
View File
@@ -127,7 +127,7 @@ public function store(Request $request)
'type' => 'nullable|in:public,private', 'type' => 'nullable|in:public,private',
'image_id' => 'nullable|exists:images,id', 'image_id' => 'nullable|exists:images,id',
'playlist_id' => 'nullable|exists:music_playlists,id', 'playlist_id' => 'nullable|exists:music_playlists,id',
'duration' => 'nullable|string|regex:/^(?:\d+:)?[0-5]?\d:[0-5]\d$/', // validates mm:ss or hh:mm:ss 'duration' => 'nullable|integer|min:1', // validates mm:ss or hh:mm:ss
]); ]);
// Handle file upload // Handle file upload
@@ -210,7 +210,7 @@ public function update(Request $request, $id)
'file' => 'nullable|mimes:mp3,wav,ogg,flac|max:20971520', 'file' => 'nullable|mimes:mp3,wav,ogg,flac|max:20971520',
'image_id' => 'nullable|exists:images,id', 'image_id' => 'nullable|exists:images,id',
'playlist_id' => 'nullable|exists:music_playlists,id', 'playlist_id' => 'nullable|exists:music_playlists,id',
'duration' => 'nullable|string|regex:/^(?:\d+:)?[0-5]?\d:[0-5]\d$/', 'duration' => 'nullable|integer|min:1',
'order' => 'nullable|integer', 'order' => 'nullable|integer',
'is_active' => 'nullable|boolean', 'is_active' => 'nullable|boolean',
]); ]);
+5 -5
View File
@@ -22,7 +22,7 @@ class Music extends Model
'playlist_id', 'image_id', 'duration', 'order', 'is_active' 'playlist_id', 'image_id', 'duration', 'order', 'is_active'
]; ];
protected $casts = [ protected $casts = [
'duration' => 'string', 'duration' => 'integer',
'order' => 'integer', 'order' => 'integer',
'is_active' => 'boolean', 'is_active' => 'boolean',
]; ];
@@ -43,10 +43,10 @@ public function tags(): BelongsToMany
return $this->belongsToMany(Tag::class, 'music_tags'); return $this->belongsToMany(Tag::class, 'music_tags');
} }
protected $appends = ['url', 'image_url' , 'average_rating', 'user_rating', 'comments_count' , 'has_user_commented', // Add this protected $appends = ['url', 'image_url' , 'average_rating', 'user_rating', 'comments_count' , 'has_user_commented',
'user_comment', // Add this 'user_comment',
'user_comment_id', // Add this 'user_comment_id',
'has_user_rated' // Add this]; 'has_user_rated'
]; ];
public function getUrlAttribute() public function getUrlAttribute()
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('music', function (Blueprint $table) {
$table->integer('duration')->nullable()->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('music', function (Blueprint $table) {
$table->string('duration')->nullable()->change();
});
}
};