TP6 et avant
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Product;
|
||||
use App\Http\Requests\StoreProductRequest;
|
||||
use App\Http\Requests\UpdateProductRequest;
|
||||
class ProductController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$search = $request->input('search');
|
||||
$query = Product::query();
|
||||
if ($search) {
|
||||
$query->where(function ($query) use ($search) {
|
||||
$query->where('name', 'like', '%' . $search . '%')
|
||||
->orWhere('price', 'like', '%' . $search . '%')
|
||||
->orWhere('stock', 'like', '%' . $search . '%');
|
||||
});
|
||||
}
|
||||
$products = $query
|
||||
->paginate(10)
|
||||
->withQueryString();
|
||||
return view('products.index', compact('products', 'search')); }
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('products.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function store(StoreProductRequest $request)
|
||||
{
|
||||
Product::create($request->validated());
|
||||
return redirect()->route('products.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Product $product)
|
||||
{
|
||||
return view('products.show', [
|
||||
'product' => $product
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Product $product)
|
||||
{
|
||||
//
|
||||
return view('products.edit', [
|
||||
'product' => $product
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(UpdateProductRequest $request, Product $product)
|
||||
{
|
||||
//
|
||||
$product->update($request->validated());
|
||||
return redirect()->route('products.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Product $product)
|
||||
{
|
||||
//
|
||||
$product->delete();
|
||||
return redirect()->route('products.index');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user