current state

This commit is contained in:
2026-02-08 10:42:01 +01:00
parent 0a4372c40d
commit e055af9248
70 changed files with 4882 additions and 330 deletions

View File

@@ -15,12 +15,19 @@ class ManageController extends Controller
$userId = $request->user()->id;
$perPage = 50;
// Use legacy connection query builder and join category name to avoid Eloquent model issues
$query = DB::connection('legacy')->table('artworks as a')
->leftJoin('artworks_categories as c', 'a.category', '=', 'c.category_id')
// Use default connection query builder and join category name to avoid Eloquent model issues
$categorySub = DB::table('artwork_category as ac')
->join('categories as c', 'ac.category_id', '=', 'c.id')
->select('ac.artwork_id', DB::raw('MIN(c.name) as category_name'))
->groupBy('ac.artwork_id');
$query = DB::table('artworks as a')
->leftJoinSub($categorySub, 'cat', function ($join) {
$join->on('a.id', '=', 'cat.artwork_id');
})
->where('a.user_id', $userId)
->select('a.*', 'c.category_name')
->orderByDesc('a.datum')
->select('a.*', DB::raw('cat.category_name as category_name'))
->orderByDesc('a.published_at')
->orderByDesc('a.id');
$artworks = $query->paginate($perPage);
@@ -34,12 +41,20 @@ class ManageController extends Controller
public function edit(Request $request, $id)
{
$userId = $request->user()->id;
$artwork = DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->first();
$artwork = DB::table('artworks')->where('id', (int)$id)->where('user_id', $userId)->first();
if (! $artwork) {
abort(404);
}
$categories = DB::connection('legacy')->table('artworks_categories')->where('section_id', 0)->orderBy('category_id')->get();
// If artworks no longer have a single `category` column, fetch pivot selection
$selectedCategory = DB::table('artwork_category')->where('artwork_id', (int)$id)->value('category_id');
$artwork->category = $selectedCategory;
$categories = DB::table('categories')
->where('content_type_id', 0)
->orderBy('id')
->select(DB::raw('id as category_id'), DB::raw('name as category_name'))
->get();
return view('manage.edit', [
'artwork' => $artwork,
@@ -51,7 +66,7 @@ class ManageController extends Controller
public function update(Request $request, $id)
{
$userId = $request->user()->id;
$existing = DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->first();
$existing = DB::table('artworks')->where('id', (int)$id)->where('user_id', $userId)->first();
if (! $existing) {
abort(404);
@@ -66,7 +81,6 @@ class ManageController extends Controller
]);
$update = [
'name' => $data['name'],
'category' => $data['section'] ?? $existing->category,
'description' => $data['description'] ?? $existing->description,
'updated' => now(),
];
@@ -86,7 +100,16 @@ class ManageController extends Controller
$update['fname'] = basename($attPath);
}
DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->update($update);
DB::table('artworks')->where('id', (int)$id)->where('user_id', $userId)->update($update);
// Update pivot: set single category selection for this artwork
if (isset($data['section'])) {
DB::table('artwork_category')->where('artwork_id', (int)$id)->delete();
DB::table('artwork_category')->insert([
'artwork_id' => (int)$id,
'category_id' => (int)$data['section'],
]);
}
return redirect()->route('manage')->with('status', 'Artwork was successfully updated.');
}
@@ -94,7 +117,7 @@ class ManageController extends Controller
public function destroy(Request $request, $id)
{
$userId = $request->user()->id;
$artwork = DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->first();
$artwork = DB::table('artworks')->where('id', (int)$id)->where('user_id', $userId)->first();
if (! $artwork) {
abort(404);
}
@@ -107,7 +130,7 @@ class ManageController extends Controller
Storage::delete('public/uploads/artworks/' . $artwork->picture);
}
DB::connection('legacy')->table('artworks')->where('id', (int)$id)->where('user_id', $userId)->delete();
DB::table('artworks')->where('id', (int)$id)->where('user_id', $userId)->delete();
return redirect()->route('manage')->with('status', 'Artwork deleted.');
}