diff --git a/app/Http/Controllers/JoinedController.php b/app/Http/Controllers/JoinedController.php index b9daa19..701d7ff 100644 --- a/app/Http/Controllers/JoinedController.php +++ b/app/Http/Controllers/JoinedController.php @@ -45,6 +45,7 @@ public function update(UpdateJoinedRequest $request, Joined $joined) public function destroy(Joined $joined) { $joined->remove(); + return redirect()->route('admin.joined.index')->with('success', 'Fanlisting removed.'); } } diff --git a/app/Http/Controllers/OwnedController.php b/app/Http/Controllers/OwnedController.php index e2b601a..fa2c349 100644 --- a/app/Http/Controllers/OwnedController.php +++ b/app/Http/Controllers/OwnedController.php @@ -35,6 +35,9 @@ public function create() */ public function store(StoreOwnedRequest $request) { + Owned::store($request->validated()); + + return redirect()->route('admin.owned.index')->with('success', 'Fanlisting added!'); } /** diff --git a/app/Http/Requests/StoreOwnedRequest.php b/app/Http/Requests/StoreOwnedRequest.php index 6d31601..06c86da 100644 --- a/app/Http/Requests/StoreOwnedRequest.php +++ b/app/Http/Requests/StoreOwnedRequest.php @@ -32,7 +32,7 @@ public function rules() 'slug' => ['required', 'alpha_dash'], 'title' => ['nullable', 'string'], 'image' => ['nullable', 'image'], - 'date_opened' => ['nullable', 'date'], + 'opened' => ['nullable', 'date'], 'hold_member_updates' => ['nullable', 'boolean'], ]; } diff --git a/app/Models/Joined.php b/app/Models/Joined.php index 4c436f6..fa6c5db 100644 --- a/app/Models/Joined.php +++ b/app/Models/Joined.php @@ -5,7 +5,6 @@ use App\Traits\Categorizable; use App\Traits\Imageable; use App\Traits\Ownable; -use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -35,15 +34,6 @@ class Joined extends Model // injected by trait: categories (morph many-to-many) - /* -------------------------------------------------------------------------- attributes ---- */ - - protected function approved() : Attribute - { - return Attribute::make( - set: fn ($value) => isset($value) ? $value = $value : $value = false, - ); - } - /* ------------------------------------------------------------------------------ joined ---- */ public static function store(array $validated) : Joined diff --git a/app/Models/Owned.php b/app/Models/Owned.php index d5988c6..59f63b2 100644 --- a/app/Models/Owned.php +++ b/app/Models/Owned.php @@ -17,5 +17,35 @@ class Owned extends Model protected $table = 'owned'; + protected $casts = [ + 'opened' => 'datetime', + 'hold_member_updates' => 'boolean', + ]; + /* ----------------------------------------------------------------------- relationships ---- */ + + // injected by trait: collective (belongsTo) + + // injected by trait: categories (many-to-many polymorphic) + + /* ------------------------------------------------------------------------------- store ---- */ + + public static function store(array $validated) : static + { + $validated['image'] = $validated['image'] ?? null; + + $owned = new static(); + $owned->subject = $validated['subject']; + $owned->status = $validated['status']; + $owned->slug = $validated['slug']; + $owned->title = $validated['title'] ?? null; + $owned->image = self::imagePath($validated['image']); + $owned->opened = $validated['opened'] ?? null; + $owned->hold_member_updates = $validated['hold_member_updates'] ?? false; + + auth_collective()->owned()->save($owned); + $owned->categories()->sync($validated['categories']); + + return $owned; + } } diff --git a/app/Traits/Imageable.php b/app/Traits/Imageable.php index 4e0e02b..c71670f 100644 --- a/app/Traits/Imageable.php +++ b/app/Traits/Imageable.php @@ -8,10 +8,10 @@ trait Imageable { public static function imagePath($image) : ?string { - $path = strtolower(static::class); + $path = strtolower(substr(strrchr(__CLASS__, '\\'), 1)); if (isset($image)) { - return Storage::putFile($path, $image); + return $image->storePublicly($path, 'public'); } else { return null; } diff --git a/resources/views/admin/owned/create.blade.php b/resources/views/admin/owned/create.blade.php index 4f25184..21b0793 100644 --- a/resources/views/admin/owned/create.blade.php +++ b/resources/views/admin/owned/create.blade.php @@ -8,7 +8,8 @@ @section('content') -
+ @csrf
@@ -18,7 +19,7 @@ - + diff --git a/resources/views/livewire/admin/list-fanlistings.blade.php b/resources/views/livewire/admin/list-fanlistings.blade.php index 8eeb7d8..a7b8cbb 100644 --- a/resources/views/livewire/admin/list-fanlistings.blade.php +++ b/resources/views/livewire/admin/list-fanlistings.blade.php @@ -1,51 +1,50 @@
+ wire:model="searchTerm" /> - - - - {{-- link --}} - - - - - + + + + {{-- link --}} + + + + + - - @foreach ($fanlistings as $fl) - - - - - + + @foreach ($fanlistings as $fl) + + + + + - + - + - - - @endforeach - -
{{-- approved --}}SubjectCategoriesImageActions
{{-- approved --}}SubjectCategoriesImageActions
- @if (!$fl->approved) - × - @endif - {{ $fl->subject }}{{ $fl->listCategories() }}
+ @if (!$fl->approved) + × + @endif + {{ $fl->subject }}{{ $fl->listCategories() }} - @if ($class == 'joined' && $fl->approved == false) - - @elseif ($class == 'owned') - View - @endif - + @if ($class == 'joined' && $fl->approved == false) + + @elseif ($class == 'owned') + View + @endif + - Edit - + Edit + - -
+ + + + + @endforeach + + - {{ $fanlistings->links() }} -
+ {{ $fanlistings->links() }} + \ No newline at end of file diff --git a/tests/Feature/Owned/CreateTest.php b/tests/Feature/Owned/CreateTest.php index d774b39..df8d5de 100644 --- a/tests/Feature/Owned/CreateTest.php +++ b/tests/Feature/Owned/CreateTest.php @@ -8,14 +8,14 @@ uses()->group('owned', 'admin'); beforeEach(function () { - $this->user = Collective::first(); + $this->user = Collective::first(); $this->request = [ 'categories' => [rand(1, 57), rand(1, 57), rand(1, 57)], 'subject' => faker()->word, 'status' => 'current', 'slug' => faker()->slug(2), 'title' => faker()->sentence(), - 'date_opened' => faker()->dateTimeThisMonth(), + 'opened' => faker()->dateTimeThisMonth(), 'hold_member_updates' => faker()->boolean(), 'notify_pending' => faker()->boolean(), ]; @@ -48,29 +48,29 @@ it('fails non-array categories', function () { $this->request['categories'] = 'This is not an array.'; - $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); + $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); $response->assertInvalid(); }); it('fails empty categories array', function () { $this->request['categories'] = []; - $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); + $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); $response->assertInvalid(); }); it('fails non-numeric category item', function () { $this->request['categories'][] = 'a'; - $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); + $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); $response->assertInvalid(); }); it('fails non-existant category', function () { - $invalidCat = (Category::all()->count()) + 10; + $invalidCat = (Category::all()->count()) + 10; $this->request['categories'][] = $invalidCat; - $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); + $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); $response->assertInvalid(); }); @@ -84,7 +84,7 @@ it('fails non-string subject', function () { $this->request['subject'] = 39502; - $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); + $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); $response->assertInvalid(); }); @@ -98,7 +98,7 @@ it('fails non-valid status', function () { $this->request['status'] = 'This is not a correct status.'; - $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); + $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); $response->assertInvalid(); }); @@ -112,7 +112,7 @@ it('fails non-valid slug format', function () { $this->request['slug'] = 'This is not a valid slug.'; - $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); + $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); $response->assertInvalid(); }); @@ -126,21 +126,21 @@ it('fails non-string title', function () { $this->request['title'] = 494920; - $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); + $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); $response->assertInvalid(); }); -it('allows null date_opened', function () { - unset($this->request['date_opened']); +it('allows null opened', function () { + unset($this->request['opened']); $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); $response->assertValid(); }); -it('fails non-date date_opened', function () { - $this->request['date_opened'] = 'This is not a date.'; - $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); +it('fails non-date opened', function () { + $this->request['opened'] = 'This is not a date.'; + $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); $response->assertInvalid(); }); @@ -154,7 +154,7 @@ it('fails non-bool hold_member_updates', function () { $this->request['holds_member_updates'] = 'This is not a boolean.'; - $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); + $response = $this->actingAs($this->user)->post('/fanatic/owned', $this->request); $response->assertInvalid(); });