Skip to content

Commit 5203464

Browse files
committed
Add code for product controller
1 parent 80e6100 commit 5203464

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

app/Http/Controllers/Api/ProductController.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@
44

55
use App\Http\Controllers\Controller;
66
use Illuminate\Http\Request;
7+
use App\Models\Product;
78

89
class ProductController extends Controller
910
{
10-
//
11+
public function index()
12+
{
13+
return Product::with(['categories' => function ($query) {
14+
$query->select('id', 'name');
15+
}])
16+
->get();
17+
}
18+
19+
public function show(Product $product)
20+
{
21+
$product->load('categories:id,name');
22+
23+
return $product;
24+
}
1125
}

0 commit comments

Comments
 (0)