-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from alimranahmed/187-cosmetic-changes-in-adm…
…in-panel 187 cosmetic changes in admin panel
- Loading branch information
Showing
16 changed files
with
333 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Image; | ||
use Illuminate\Support\Facades\Storage; | ||
use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
|
||
class FileController extends Controller | ||
{ | ||
public function path($uuid): BinaryFileResponse | ||
{ | ||
/** @var ?Image $image */ | ||
$image = Image::query()->where('uuid', $uuid)->firstOrFail(); | ||
|
||
return response()->download(Storage::path($image->src)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\Livewire\Backend\Article; | ||
|
||
use App\Models\Image; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Support\Str; | ||
use Livewire\Attributes\Validate; | ||
use Livewire\Component; | ||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; | ||
use Livewire\WithFileUploads; | ||
|
||
class ImageForm extends Component | ||
{ | ||
use WithFileUploads; | ||
|
||
#[Validate(['image' => 'image|max:2048'])] // 2MB | ||
public null|TemporaryUploadedFile $image = null; | ||
|
||
public array $files = []; | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.backend.article.image-form'); | ||
} | ||
|
||
public function updatedImage(): void | ||
{ | ||
$this->validate(); | ||
$this->save(); | ||
} | ||
|
||
public function save(): void | ||
{ | ||
$path = $this->image->store(path: 'images'); | ||
|
||
/** @var Image $image */ | ||
$image = Image::query()->create([ | ||
'uuid' => Str::uuid(), | ||
'src' => $path, | ||
'src_type' => 'internal', | ||
]); | ||
|
||
$this->files[] = [ | ||
'name' => $this->image->getClientOriginalName(), | ||
'url' => route('file', [$image->uuid]), | ||
'size' => $this->formatFileSize($this->image->getSize()), | ||
]; | ||
} | ||
|
||
private function formatFileSize(int $bytes, int $precision = 2): string | ||
{ | ||
$units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB']; | ||
|
||
if ($bytes == 0) { | ||
return '0 Bytes'; | ||
} | ||
|
||
$index = floor(log($bytes, 1024)); // Find the appropriate unit | ||
$fileSize = $bytes / pow(1024, $index); // Convert size to the appropriate unit | ||
|
||
return round($fileSize, $precision) . ' ' . $units[$index]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
database/migrations/2024_09_12_230821_add_uuid_in_images_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('images', function (Blueprint $table) { | ||
$table->uuid()->after('id'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('images', function (Blueprint $table) { | ||
$table->dropColumn('uuid'); | ||
}); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
@props(['name']) | ||
|
||
<select name="{{$name}}" | ||
{{$attributes->merge(['class' => 'block p-1 border border-indigo-300 rounded focus:outline-none focus:border-indigo-500'])}} | ||
<select name="{{$name}}" | ||
{{$attributes->merge(['class' => 'block p-1 border border-indigo-300 rounded focus:outline-none focus:ring-0 focus:border-indigo-500'])}} | ||
> | ||
{{$slot}} | ||
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
@props(['type' => 'text', 'name']) | ||
@props(['type' => 'text', 'name', 'rounded' => true]) | ||
|
||
@php | ||
$class = $rounded ? 'rounded' : ''; | ||
@endphp | ||
|
||
<textarea type="{{$type}}" name="{{$name}}" | ||
{{$attributes->merge(['class' => 'p-1 border border-indigo-300 rounded focus:outline-none focus:border-indigo-500'])}} | ||
{{$attributes->merge(['class' => "p-1 border border-indigo-300 focus:outline-none focus:ring-0 focus:border-indigo-500 $class"])}} | ||
>{{$slot}}</textarea> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.