- Fix Blade parse error in admin AI settings (Blade was interpreting
JSON braces in DEFAULT_PROMPT as template tags, breaking the navbar)
— pass defaultPrompt from controller instead
- Add rescan: POST /nail-polishes/{id}/rescan creates a new import for
an existing nail polish and updates its fields after AI analysis
- Add KI-Rescan button on collection cards (only if image exists)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
89 lines
2.6 KiB
PHP
89 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Jobs\ProcessNailPolishImage;
|
|
use App\Models\NailPolish;
|
|
use App\Models\NailPolishImport;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Intervention\Image\ImageManager;
|
|
use Intervention\Image\Drivers\Gd\Driver;
|
|
|
|
class NailPolishImportController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$imports = NailPolishImport::where('user_id', auth()->id())
|
|
->latest()
|
|
->paginate(20);
|
|
|
|
return view('nail-polish-imports.index', compact('imports'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('nail-polish-imports.create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'image' => 'required|image|mimes:jpeg,png,jpg,webp|max:10240',
|
|
]);
|
|
|
|
$file = $request->file('image');
|
|
$filename = 'nail-polish-imports/' . uniqid() . '.jpg';
|
|
|
|
$manager = new ImageManager(new Driver());
|
|
$image = $manager->read($file->getRealPath());
|
|
|
|
// Auf max. 1200px skalieren und als JPEG mit 85% Qualität speichern
|
|
$image->scaleDown(width: 1200, height: 1200);
|
|
Storage::disk('public')->put($filename, $image->toJpeg(85));
|
|
|
|
$path = $filename;
|
|
|
|
$import = NailPolishImport::create([
|
|
'user_id' => auth()->id(),
|
|
'image_path' => $path,
|
|
'status' => 'pending',
|
|
]);
|
|
|
|
ProcessNailPolishImage::dispatch($import->id);
|
|
|
|
$redirectUrl = route('nail-polish-imports.show', $import);
|
|
|
|
if (request()->ajax()) {
|
|
return response()->json(['redirect' => $redirectUrl]);
|
|
}
|
|
|
|
return redirect($redirectUrl)
|
|
->with('success', 'Bild hochgeladen! Die KI analysiert es jetzt im Hintergrund.');
|
|
}
|
|
|
|
public function show(NailPolishImport $nailPolishImport)
|
|
{
|
|
abort_if($nailPolishImport->user_id !== auth()->id(), 403);
|
|
|
|
return view('nail-polish-imports.show', ['import' => $nailPolishImport->load('nailPolish.manufacturer')]);
|
|
}
|
|
|
|
public function rescan(NailPolish $nailPolish)
|
|
{
|
|
abort_unless($nailPolish->image_path, 404);
|
|
|
|
$import = NailPolishImport::create([
|
|
'user_id' => auth()->id(),
|
|
'image_path' => $nailPolish->image_path,
|
|
'status' => 'pending',
|
|
'nail_polish_id' => $nailPolish->id,
|
|
]);
|
|
|
|
ProcessNailPolishImage::dispatch($import->id);
|
|
|
|
return redirect()->route('nail-polish-imports.show', $import)
|
|
->with('success', 'KI-Analyse gestartet. Die Daten werden aktualisiert.');
|
|
}
|
|
}
|