From afce441001319a03405b672b654bfda2bae71378 Mon Sep 17 00:00:00 2001 From: Ro Date: Wed, 16 Aug 2023 17:52:02 -0700 Subject: [PATCH] Rewired new location submission form Brought over the old form for adding new location to the db and the plugged everything back up using Laravel's eloquent orm (which is pretty fucking sweet) to re-active that process NOTE: larvel gets a twitchy when sequencing isn't explicitly set some minor edits needed to be made to the development DB to prevent a null id error when inserting new records. this should be done to production when it's ready as well --- app/Http/Controllers/DenController.php | 6 +++ app/Http/Controllers/LocationController.php | 40 ++++++++++++++++++++ app/Models/Location.php | 16 +++++++- config/filesystems.php | 39 +++++++++++-------- public/reference | 1 + resources/views/back/locations.blade.php | 29 ++++++++++++++ resources/views/forms/add-location.blade.php | 29 ++++++++++++++ routes/web.php | 3 ++ 8 files changed, 146 insertions(+), 17 deletions(-) create mode 120000 public/reference create mode 100644 resources/views/forms/add-location.blade.php diff --git a/app/Http/Controllers/DenController.php b/app/Http/Controllers/DenController.php index 14bfc9d..f97e707 100644 --- a/app/Http/Controllers/DenController.php +++ b/app/Http/Controllers/DenController.php @@ -19,4 +19,10 @@ class DenController extends Controller $member = Auth::user(); return view('back.member', ['handle' => $member->handle]); } + + public function location(Request $request, string $action = "index") + { + $member = Auth::user(); + return view('back.locations', ['handle' => $member->handle, "action" => $action]); + } } diff --git a/app/Http/Controllers/LocationController.php b/app/Http/Controllers/LocationController.php index 6f75150..7b5b0a1 100644 --- a/app/Http/Controllers/LocationController.php +++ b/app/Http/Controllers/LocationController.php @@ -3,8 +3,48 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\Models\Location; +use Ramsey\Uuid\Uuid; +use Illuminate\Support\Facades\Auth; class LocationController extends Controller { // + public function addLocation(Request $request) + { + $fields = $request->validate([ + 'name' => ['required'], + 'url' => ['required'], + 'description' => ['required'], + 'tags' => ['required'], + ]); + + if ($fields) { + $examples = []; + $files = $request->files->get("loc_examples"); + if ($request->hasfile('loc_examples')) { + foreach ($request->file('loc_examples') as $file) { + $path = $file->store('reference'); + array_push($examples, ["path" => $path]); + } + } + $request->merge(['active' => true]); + $request->merge(['uuid' => Uuid::uuid4()]); + $request->merge(['images' => json_encode($examples)]); + $request->merge(['added_by' => Auth::user()->id]); + //NOTE: Laravel gets funky if sequencing isn't explicitly set + $new = Location::create($request->all()); + if ($new) { + return back()->with('message', 'New Location Added. Take a break!'); + } else { + return back()->withErrors([ + 'error' => 'Uh oh. There was an inssue', + ]); + } + } else { + return back()->withErrors([ + 'error' => 'All fields are required', + ]); + } + } } diff --git a/app/Models/Location.php b/app/Models/Location.php index d0df884..3b10a77 100644 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -9,6 +9,18 @@ class Location extends Model { use HasFactory; - protected $table = "location"; - protected $fillable = ["uuid", "name", "url", "description", "images", "active", "rating", "added_by", "tags"]; + /** + * The table associated with the model. + * + * @var string + */ + protected $table = "location"; + + protected $primaryKey = 'id'; + public $incrementing = true; + protected $fillable = [ + "id", + "uuid", + "name", + "url", "description", "images", "active", "rating", "added_by", "tags", "created_at", "updated_at"]; } diff --git a/config/filesystems.php b/config/filesystems.php index e9d9dbd..e4725ad 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -32,28 +32,36 @@ return [ 'local' => [ 'driver' => 'local', - 'root' => storage_path('app'), - 'throw' => false, + 'root' => storage_path('app'), + 'throw' => false, ], 'public' => [ - 'driver' => 'local', - 'root' => storage_path('app/public'), - 'url' => env('APP_URL').'/storage', + 'driver' => 'local', + 'root' => storage_path('app/public'), + 'url' => env('APP_URL') . '/storage', + 'visibility' => 'public', + 'throw' => false, + ], + + 'reference' => [ + 'driver' => 'local', + 'root' => storage_path('app/reference'), + 'url' => env('APP_URL') . '/reference', 'visibility' => 'public', - 'throw' => false, + 'throw' => false, ], 's3' => [ - 'driver' => 's3', - 'key' => env('AWS_ACCESS_KEY_ID'), - 'secret' => env('AWS_SECRET_ACCESS_KEY'), - 'region' => env('AWS_DEFAULT_REGION'), - 'bucket' => env('AWS_BUCKET'), - 'url' => env('AWS_URL'), - 'endpoint' => env('AWS_ENDPOINT'), + 'driver' => 's3', + 'key' => env('AWS_ACCESS_KEY_ID'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'region' => env('AWS_DEFAULT_REGION'), + 'bucket' => env('AWS_BUCKET'), + 'url' => env('AWS_URL'), + 'endpoint' => env('AWS_ENDPOINT'), 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), - 'throw' => false, + 'throw' => false, ], ], @@ -70,7 +78,8 @@ return [ */ 'links' => [ - public_path('storage') => storage_path('app/public'), + public_path('storage') => storage_path('app/public'), + public_path('reference') => storage_path('app/reference'), ], ]; diff --git a/public/reference b/public/reference new file mode 120000 index 0000000..3cf38b9 --- /dev/null +++ b/public/reference @@ -0,0 +1 @@ +/Users/ro/Projects/TheBadSpace/first/storage/app/reference \ No newline at end of file diff --git a/resources/views/back/locations.blade.php b/resources/views/back/locations.blade.php index e69de29..8bff2b5 100644 --- a/resources/views/back/locations.blade.php +++ b/resources/views/back/locations.blade.php @@ -0,0 +1,29 @@ +@extends('frame') + +@section('title', 'Den|Locations') + + @section('main-content') + @parent + @if($errors->any()) +

{{$errors->first()}}

+ @endif + @if(session('message')) + {!! session('message') !!} + @endif +
+
+

Locations

+ Hey {{$handle}}
+ + @if($action === "add") + @include('forms.add-location') + @elseif($action === "edit") + EDIT LOCATION + @elseif($action === "bulk-add") + ADD MANY LOCATIONS + @else + START + @endif +
+
+ @endsection \ No newline at end of file diff --git a/resources/views/forms/add-location.blade.php b/resources/views/forms/add-location.blade.php new file mode 100644 index 0000000..a8dd338 --- /dev/null +++ b/resources/views/forms/add-location.blade.php @@ -0,0 +1,29 @@ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ @csrf + + +
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index fc3fd94..41a6533 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\FrontIndexController; use App\Http\Controllers\AuthController; use App\Http\Controllers\DenController; +use App\Http\Controllers\LocationController; /* |-------------------------------------------------------------------------- @@ -28,4 +29,6 @@ Route::get("/logout", [AuthController::class, 'leave']); Route::group(['prefix' => 'den', 'middleware' => 'member.check'], function () { Route::get("/", [DenController::class, 'start']); Route::get("/member", [DenController::class, 'member']); + Route::get("/locations/{action?}", [DenController::class, 'location']); + Route::post("/locations/add", [LocationController::class, 'addLocation']); });