Etude index working

This commit is contained in:
Matt Young 2025-12-18 09:20:07 -06:00
parent f7c75fa1f9
commit e9a6379438
7 changed files with 230 additions and 6 deletions

View File

@ -17,6 +17,7 @@ This application is a Laravel application and its main Laravel ecosystems packag
- laravel/sail (SAIL) - v1 - laravel/sail (SAIL) - v1
- pestphp/pest (PEST) - v3 - pestphp/pest (PEST) - v3
- phpunit/phpunit (PHPUNIT) - v11 - phpunit/phpunit (PHPUNIT) - v11
- alpinejs (ALPINEJS) - v3
- tailwindcss (TAILWINDCSS) - v4 - tailwindcss (TAILWINDCSS) - v4
## Conventions ## Conventions

View File

@ -17,6 +17,7 @@ This application is a Laravel application and its main Laravel ecosystems packag
- laravel/sail (SAIL) - v1 - laravel/sail (SAIL) - v1
- pestphp/pest (PEST) - v3 - pestphp/pest (PEST) - v3
- phpunit/phpunit (PHPUNIT) - v11 - phpunit/phpunit (PHPUNIT) - v11
- alpinejs (ALPINEJS) - v3
- tailwindcss (TAILWINDCSS) - v4 - tailwindcss (TAILWINDCSS) - v4
## Conventions ## Conventions

View File

@ -7,6 +7,7 @@ use App\Models\AuditionedEnsemble;
use App\Models\AuditionEtude; use App\Models\AuditionEtude;
use App\Models\Instrument; use App\Models\Instrument;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class AuditionEtudeController extends Controller class AuditionEtudeController extends Controller
{ {
@ -15,7 +16,9 @@ class AuditionEtudeController extends Controller
*/ */
public function index() public function index()
{ {
return view('admin.audition_etude.index'); $etudes = AuditionEtude::paginate(10);
return view('admin.audition_etude.index', compact('etudes'));
} }
/** /**
@ -37,7 +40,12 @@ class AuditionEtudeController extends Controller
*/ */
public function store(EtudeUploadRequest $request) public function store(EtudeUploadRequest $request)
{ {
$path = $request->file('file_upload')->store('etudes', 'public'); $instrument = Instrument::find($request->instrument_id);
$ensemble = AuditionedEnsemble::find($request->auditioned_ensemble_id);
$filename = $ensemble->name.' '.$instrument->instrument.' Set '.$request->set.'.pdf';
$filename = str_replace(' ', '_', $filename);
$path = $request->file('file_upload')->storeAs('etudes', $filename, 'public');
$originalFilename = $request->file('file_upload')->getClientOriginalName(); $originalFilename = $request->file('file_upload')->getClientOriginalName();
$fileSize = $request->file('file_upload')->getSize(); $fileSize = $request->file('file_upload')->getSize();
@ -80,8 +88,11 @@ class AuditionEtudeController extends Controller
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
*/ */
public function destroy(AuditionEtude $auditionEtude) public function destroy(AuditionEtude $etude)
{ {
// Storage::disk('public')->delete('/'.$etude->file_path);
$etude->delete();
return redirect()->route('admin.etudes.index')->with('success', 'Etude deleted successfully.');
} }
} }

View File

@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -20,4 +21,24 @@ class AuditionEtude extends Model
{ {
return $this->belongsTo(AuditionedEnsemble::class); return $this->belongsTo(AuditionedEnsemble::class);
} }
protected function humanReadableFileSize(): Attribute
{
return Attribute::make(
get: function () {
$bytes = $this->file_size;
if ($bytes === null) {
return 'N/A';
}
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, 2).' '.$units[$pow];
}
);
}
} }

View File

@ -10,6 +10,7 @@
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": "^8.2", "php": "^8.2",
"blade-ui-kit/blade-heroicons": "^2.6",
"laravel/fortify": "^1.32", "laravel/fortify": "^1.32",
"laravel/framework": "^12.0", "laravel/framework": "^12.0",
"laravel/prompts": "^0.3.8", "laravel/prompts": "^0.3.8",

152
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "bd377529b45b2db07fbfd360dccb505c", "content-hash": "5157014187d3ae76a3586965840ec1f0",
"packages": [ "packages": [
{ {
"name": "bacon/bacon-qr-code", "name": "bacon/bacon-qr-code",
@ -61,6 +61,156 @@
}, },
"time": "2025-11-19T17:15:36+00:00" "time": "2025-11-19T17:15:36+00:00"
}, },
{
"name": "blade-ui-kit/blade-heroicons",
"version": "2.6.0",
"source": {
"type": "git",
"url": "https://github.com/driesvints/blade-heroicons.git",
"reference": "4553b2a1f6c76f0ac7f3bc0de4c0cfa06a097d19"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/driesvints/blade-heroicons/zipball/4553b2a1f6c76f0ac7f3bc0de4c0cfa06a097d19",
"reference": "4553b2a1f6c76f0ac7f3bc0de4c0cfa06a097d19",
"shasum": ""
},
"require": {
"blade-ui-kit/blade-icons": "^1.6",
"illuminate/support": "^9.0|^10.0|^11.0|^12.0",
"php": "^8.0"
},
"require-dev": {
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
"phpunit/phpunit": "^9.0|^10.5|^11.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"BladeUI\\Heroicons\\BladeHeroiconsServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"BladeUI\\Heroicons\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Dries Vints",
"homepage": "https://driesvints.com"
}
],
"description": "A package to easily make use of Heroicons in your Laravel Blade views.",
"homepage": "https://github.com/blade-ui-kit/blade-heroicons",
"keywords": [
"Heroicons",
"blade",
"laravel"
],
"support": {
"issues": "https://github.com/driesvints/blade-heroicons/issues",
"source": "https://github.com/driesvints/blade-heroicons/tree/2.6.0"
},
"funding": [
{
"url": "https://github.com/sponsors/driesvints",
"type": "github"
},
{
"url": "https://www.paypal.com/paypalme/driesvints",
"type": "paypal"
}
],
"time": "2025-02-13T20:53:33+00:00"
},
{
"name": "blade-ui-kit/blade-icons",
"version": "1.8.0",
"source": {
"type": "git",
"url": "https://github.com/driesvints/blade-icons.git",
"reference": "7b743f27476acb2ed04cb518213d78abe096e814"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/driesvints/blade-icons/zipball/7b743f27476acb2ed04cb518213d78abe096e814",
"reference": "7b743f27476acb2ed04cb518213d78abe096e814",
"shasum": ""
},
"require": {
"illuminate/contracts": "^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/filesystem": "^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/view": "^8.0|^9.0|^10.0|^11.0|^12.0",
"php": "^7.4|^8.0",
"symfony/console": "^5.3|^6.0|^7.0",
"symfony/finder": "^5.3|^6.0|^7.0"
},
"require-dev": {
"mockery/mockery": "^1.5.1",
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0|^10.0",
"phpunit/phpunit": "^9.0|^10.5|^11.0"
},
"bin": [
"bin/blade-icons-generate"
],
"type": "library",
"extra": {
"laravel": {
"providers": [
"BladeUI\\Icons\\BladeIconsServiceProvider"
]
}
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"BladeUI\\Icons\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Dries Vints",
"homepage": "https://driesvints.com"
}
],
"description": "A package to easily make use of icons in your Laravel Blade views.",
"homepage": "https://github.com/blade-ui-kit/blade-icons",
"keywords": [
"blade",
"icons",
"laravel",
"svg"
],
"support": {
"issues": "https://github.com/blade-ui-kit/blade-icons/issues",
"source": "https://github.com/blade-ui-kit/blade-icons"
},
"funding": [
{
"url": "https://github.com/sponsors/driesvints",
"type": "github"
},
{
"url": "https://www.paypal.com/paypalme/driesvints",
"type": "paypal"
}
],
"time": "2025-02-13T20:35:06+00:00"
},
{ {
"name": "brick/math", "name": "brick/math",
"version": "0.14.1", "version": "0.14.1",

View File

@ -1,4 +1,43 @@
<x-layout.admin> <x-layout.admin>
<x-form.button href="{{ route('admin.etudes.create') }}" type="link">Add Etude</x-form.button> <x-form.button href="{{ route('admin.etudes.create') }}" type="link">Add Etude</x-form.button>
<p>Audition Etude Index</p> <x-card class="mt-3">
<x-slot:header class="bg-brand-600!">Etudes</x-slot:header>
<x-slot:body class="bg-white border border-brand-600">
<x-table>
<x-slot:header>
<x-table.th>Ensemble</x-table.th>
<x-table.th>Set</x-table.th>
<x-table.th>Instrument</x-table.th>
<x-table.th>Link</x-table.th>
<x-table.th>Original Filename</x-table.th>
<x-table.th>Size</x-table.th>
<x-table.th></x-table.th>
</x-slot:header>
@foreach($etudes as $etude)
<tr>
<x-table.td>{{ $etude->auditionedEnsemble->name }}</x-table.td>
<x-table.td>{{ $etude->set }}</x-table.td>
<x-table.td>{{ $etude->instrument->instrument }}</x-table.td>
<x-table.td>
<a href="/{{ $etude->file_path }}" target="_new">
<x-heroicon-o-arrow-down-tray class="w-5"/>
</a>
</x-table.td>
<x-table.td>{{ $etude->original_filename }}</x-table.td>
<x-table.td>{{ $etude->human_readable_file_size }}</x-table.td>
<x-table.td>
<x-form method="DELETE" action="{{ route('admin.etudes.destroy', $etude) }}">
<button type="submit">
<x-heroicon-o-trash class="w-5"/>
</button>
</x-form>
</x-table.td>
</tr>
@endforeach
</x-table>
<div class="mt-3 px-4">
{{ $etudes->links() }}
</div>
</x-slot:body>
</x-card>
</x-layout.admin> </x-layout.admin>