Init commit
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Pricelist;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PricelistController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$pricelist = Pricelist::where('is_active', true)
|
||||
->orderBy('sort_order')
|
||||
->orderBy('title')
|
||||
->get();
|
||||
|
||||
return response()->json($pricelist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'required|string',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'sort_order' => 'integer|min:0',
|
||||
'is_active' => 'boolean'
|
||||
]);
|
||||
|
||||
$pricelist = Pricelist::create($request->all());
|
||||
|
||||
return response()->json($pricelist, 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
$pricelist = Pricelist::findOrFail($id);
|
||||
return response()->json($pricelist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
$request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'required|string',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'sort_order' => 'integer|min:0',
|
||||
'is_active' => 'boolean'
|
||||
]);
|
||||
|
||||
$pricelist = Pricelist::findOrFail($id);
|
||||
$pricelist->update($request->all());
|
||||
|
||||
return response()->json($pricelist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
$pricelist = Pricelist::findOrFail($id);
|
||||
$pricelist->delete();
|
||||
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all pricelist items (including inactive) for admin management
|
||||
*/
|
||||
public function adminIndex()
|
||||
{
|
||||
$pricelist = Pricelist::orderBy('sort_order')
|
||||
->orderBy('title')
|
||||
->get();
|
||||
|
||||
return response()->json($pricelist);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user