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
remotes/alcapurrias/about-updates
Ro 2023-08-16 17:52:02 -07:00
parent 66cf78ba75
commit afce441001
No known key found for this signature in database
GPG Key ID: 29B551CDBD4D3B50
8 changed files with 146 additions and 17 deletions

View File

@ -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]);
}
}

View File

@ -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',
]);
}
}
}

View File

@ -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"];
}

View File

@ -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,
'throw' => false,
],
'reference' => [
'driver' => 'local',
'root' => storage_path('app/reference'),
'url' => env('APP_URL') . '/reference',
'visibility' => 'public',
'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'),
],
];

1
public/reference Symbolic link
View File

@ -0,0 +1 @@
/Users/ro/Projects/TheBadSpace/first/storage/app/reference

View File

@ -0,0 +1,29 @@
@extends('frame')
@section('title', 'Den|Locations')
@section('main-content')
@parent
@if($errors->any())
<h4>{{$errors->first()}}</h4>
@endif
@if(session('message'))
{!! session('message') !!}
@endif
<section role="loc-index">
<div>
<h1>Locations</h1>
Hey {{$handle}}<br />
@if($action === "add")
@include('forms.add-location')
@elseif($action === "edit")
EDIT LOCATION
@elseif($action === "bulk-add")
ADD MANY LOCATIONS
@else
START
@endif
</div>
</section>
@endsection

View File

@ -0,0 +1,29 @@
<form action="/den/locations/add" method="post" enctype="multipart/form-data">
<div>
<label>Name</label><br />
<input type="text" name="name" value="" />
<br />
<label>URL</label><br />
<input type="text" name="url" value="" />
<br />
<label>Tags</label><br />
<input type="text" name="tags" value="" />
<br />
<label>Description</label><br />
<textarea name="description"></textarea>
<br />
<label>Rating</label><br />
<select name="rating">
<option value="" disabled selected>Choose Rating
</option>
<option value="silence">Silence</option>
<option value="defederate">Defederate</option>
</select>
<br />
<label>Images</label><br />
<input type="file" id="loc_examples" name="loc_examples[]" multiple />
</div>
@csrf
<input type="hidden" name="mode" value="add" />
<input type="submit" value="Edit Location" name="submit_button">
</form>

View File

@ -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']);
});