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') -