Add product status tabs, persist user collection seeding, and enhance staging visibility
This commit is contained in:
@@ -17,13 +17,26 @@ class ProductController extends Controller
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$query = Product::with('category')->latest();
|
||||
$tab = $request->query('tab', 'all');
|
||||
$query = Product::with(['category', 'makerworldCollection'])->latest();
|
||||
|
||||
if ($tab === 'published') {
|
||||
$query->where(function ($q) {
|
||||
$q->where('status', 'published')
|
||||
->orWhereNull('status');
|
||||
});
|
||||
} elseif ($tab === 'draft') {
|
||||
$query->where('status', 'draft');
|
||||
} elseif ($tab === 'makerworld') {
|
||||
$query->whereNotNull('makerworld_id');
|
||||
}
|
||||
|
||||
if ($request->filled('q')) {
|
||||
$q = $request->input('q');
|
||||
$query->where(function ($w) use ($q) {
|
||||
$w->where('name', 'like', "%{$q}%")
|
||||
->orWhere('description', 'like', "%{$q}%");
|
||||
->orWhere('description', 'like', "%{$q}%")
|
||||
->orWhere('makerworld_id', 'like', "%{$q}%");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,10 +44,23 @@ class ProductController extends Controller
|
||||
$query->where('category_id', $request->input('category_id'));
|
||||
}
|
||||
|
||||
$totalAll = Product::count();
|
||||
$totalPublished = Product::where('status', 'published')->orWhereNull('status')->count();
|
||||
$totalDraft = Product::where('status', 'draft')->count();
|
||||
$totalMakerWorld = Product::whereNotNull('makerworld_id')->count();
|
||||
|
||||
$products = $query->paginate(20)->withQueryString();
|
||||
$categories = Category::all();
|
||||
|
||||
return view('admin.products.index', compact('products', 'categories'));
|
||||
return view('admin.products.index', compact(
|
||||
'products',
|
||||
'categories',
|
||||
'tab',
|
||||
'totalAll',
|
||||
'totalPublished',
|
||||
'totalDraft',
|
||||
'totalMakerWorld'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user