mirror of
https://koodu.h-i.works/projects/thebadspace
synced 2025-06-25 16:04:37 -05:00
Cleaned up location controller, responsive fix
The Location Controller was getting too heavy so an Update and Maintenance service class was created to offload most of it's functionality. Location upating was moved to LocationRepository There was also a small issue with responsive list links not adapting properly in Safari that was fixed
This commit is contained in:
@ -4,6 +4,7 @@ namespace App\Repositories;
|
||||
|
||||
use App\Models\Location;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class LocationRepository
|
||||
{
|
||||
@ -70,4 +71,42 @@ class LocationRepository
|
||||
|
||||
return $result = [$locations, $pageCount, $prev, $next];
|
||||
}
|
||||
|
||||
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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user