mirror of
https://github.com/serialexperiments0815/Dilomarkt---Digitaler-Lokalmarkt.git
synced 2026-07-12 15:32:19 +00:00
28 lines
821 B
PHP
28 lines
821 B
PHP
<?php
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ProviderController extends Controller {
|
|
|
|
public function index() {
|
|
return response()->json(DB::table('providers')->get());
|
|
}
|
|
|
|
public function show(int $id) {
|
|
$provider = DB::table('providers')->where('id', $id)->first();
|
|
if (!$provider) return response()->json(['error' => 'Not found'], 404);
|
|
|
|
$products = DB::table('products')
|
|
->where('provider_id', $id)
|
|
->get();
|
|
|
|
$stats = [
|
|
'product_count' => $products->count(),
|
|
'total_stock' => $products->sum('stock'),
|
|
'min_price' => $products->min('price'),
|
|
];
|
|
|
|
return response()->json(['provider' => $provider, 'products' => $products, 'stats' => $stats]);
|
|
}
|
|
}
|