Compare commits

..

No commits in common. 'd1c4f395918f9a634abe775af9b3c5dc73e9b213' and 'cbbe61265877630440d81eb3d82a22b44c23ed43' have entirely different histories.

@ -63,10 +63,10 @@ class User extends Authenticatable
'username' => 'required|string', 'username' => 'required|string',
'email' => 'required|email', 'email' => 'required|email',
'password' => 'required_without:id|string|min:8', 'password' => 'required_without:id|string|min:8',
'is_active' => 'required_with:id|boolean', 'is_active' => 'required_with:id|in:true,false',
], [ ], [
'password.required_without' => 'The password field is required.', 'password' => ['required_with' => 'The password field is required.'],
'is_active.required_with' => 'The is active field is required.' 'is_active' => ['required_with' => 'The is active field is required.']
]); ]);
try { try {

@ -24,7 +24,7 @@ class VideoUpdate extends Model {
protected $table = 'video_updates'; protected $table = 'video_updates';
protected $hidden = ['file']; protected $hidden = ['file'];
protected $appends = ['file_url', 'file_size_mb']; protected $appends = ['file_url'];
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// -- RELATED TO SCOPE // -- RELATED TO SCOPE
@ -40,22 +40,12 @@ class VideoUpdate extends Model {
// -- END RELATED TO GET DATA // -- END RELATED TO GET DATA
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
// -- RELATED TO ATTRIBUTE
protected function fileSizeMb(): Attribute {
return Attribute::make(
fn() => $this->file_size_kb != null ? round($this->file_size_kb / 1024, 2) : null
);
}
// -- END RELATED TO ATTRIBUTE
// ---------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// -- RELATED TO MODIFICATION DATA FROM REQUEST // -- RELATED TO MODIFICATION DATA FROM REQUEST
public static function upsertFromRequest(Request $request) { public static function upsertFromRequest(Request $request) {
$request->validate([ $request->validate([
'id' => 'nullable|integer|exists:App\Models\VideoUpdate,id', 'id' => 'nullable|integer|exists:App\Models\VideoUpdate,id',
'is_selected' => 'nullable|boolean', 'is_selected' => 'nullable|in:true,false',
'file' => 'required_without:id|file|' . FileHelper::convertToStrLaraValidation(FileHelper::$allowedVideoExtensions), 'file' => 'required_without:id|file|' . FileHelper::convertToStrLaraValidation(FileHelper::$allowedVideoExtensions),
'file_name' => 'required|string', 'file_name' => 'required|string',
], [ ], [
@ -64,13 +54,9 @@ class VideoUpdate extends Model {
$delOldDbFileLocation = ''; $delOldDbFileLocation = '';
$newDbFileLocation = ''; $newDbFileLocation = '';
$newFileSizeKb = 0;
try { try {
// save video to storage & get file size // save photo
if($request->file) { if($request->file) $newDbFileLocation = self::saveFile($request->file)['db_url'];
$newDbFileLocation = self::saveFile($request->file)['db_url'];
$newFileSizeKb = round($request->file('file')->getSize() / 1024, 2);
}
// try to upsert data // try to upsert data
DB::beginTransaction(); DB::beginTransaction();
@ -82,7 +68,6 @@ class VideoUpdate extends Model {
if($newDbFileLocation) { if($newDbFileLocation) {
if($videoUpdate->file) $delOldDbFileLocation = $videoUpdate->file; if($videoUpdate->file) $delOldDbFileLocation = $videoUpdate->file;
$videoUpdate->file = $newDbFileLocation; $videoUpdate->file = $newDbFileLocation;
$videoUpdate->file_size_kb = $newFileSizeKb;
} }
$videoUpdate->file_name = $request->file_name; $videoUpdate->file_name = $request->file_name;

@ -1,26 +0,0 @@
<?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('video_updates', function(Blueprint $table) {
$table->double('file_size_kb')->default(0);
});
}
/**
* Reverse the migrations.
*/
public function down(): void {
Schema::table('video_updates', function(Blueprint $table) {
$table->dropColumn('file_size_kb');
});
}
};
Loading…
Cancel
Save