Migrate HickLab3D dashboard and add production auto deployment
Deploy HickLab3D Dashboard / Deploy to production (push) Failing after 19s
Deploy HickLab3D Dashboard / Deploy to production (push) Failing after 19s
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Filament;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class FilamentController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
return view('filaments.index', ['filaments' => Filament::with(['prices' => fn ($query) => $query->orderByDesc('recordedAt')->limit(10)])->orderBy('filamentName')->paginate(20)]);
|
||||
}
|
||||
|
||||
public function create(Request $request): View
|
||||
{
|
||||
abort_unless($request->user()->role === 'admin', 403);
|
||||
|
||||
return view('filaments.create');
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
abort_unless($request->user()->role === 'admin', 403);
|
||||
$data = $request->validate([
|
||||
'filamentName' => ['required', 'string', 'max:255'],
|
||||
'amazonUrl' => ['required', 'url:http,https', 'max:2048'],
|
||||
'brand' => ['nullable', 'string', 'max:255'],
|
||||
'material' => ['nullable', 'string', 'max:255'],
|
||||
'color' => ['nullable', 'string', 'max:255'],
|
||||
'filamentWeight' => ['nullable', 'numeric', 'min:0'],
|
||||
'itemDiameter' => ['nullable', 'numeric', 'min:0'],
|
||||
]);
|
||||
$host = strtolower((string) parse_url($data['amazonUrl'], PHP_URL_HOST));
|
||||
if (! in_array($host, ['amazon.co.uk', 'www.amazon.co.uk', 'amazon.com', 'www.amazon.com'], true)) {
|
||||
return back()->withErrors(['amazonUrl' => 'Enter an Amazon UK or US product URL.'])->withInput();
|
||||
}
|
||||
Filament::create([...$data, 'userId' => $request->user()->id]);
|
||||
|
||||
return redirect()->route('filaments.index')->with('status', 'Filament added. Price collection runs on the schedule.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Filament $filament): RedirectResponse
|
||||
{
|
||||
abort_unless($request->user()->role === 'admin', 403);
|
||||
$filament->delete();
|
||||
|
||||
return redirect()->route('filaments.index')->with('status', 'Filament removed.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user