Create routes and views for suppliers.

This commit is contained in:
2025-02-10 12:47:57 +01:00
parent 3f07d333df
commit 7c085dfa6b
12 changed files with 664 additions and 12 deletions

View File

@@ -5,13 +5,68 @@ namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Supplier;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class SupplierController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(): JsonResponse
{
$suppliers = Supplier::orderBy('name')->get();
$suppliers = Supplier::orderBy('name')->with(['invoices'])->get();
return response()->json($suppliers);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): JsonResponse
{
$supplierData = $request->validate([
'name' => 'required|string',
'registration_name' => 'nullable|string',
'email' => 'nullable|email',
'address' => 'nullable|string',
'city' => 'nullable|string',
'zip' => 'nullable|string',
'country_code' => 'nullable|string',
'tax_fc' => 'nullable|string',
'tax_vat' => 'nullable|string',
'contact_name' => 'nullable|string',
'contact_phone' => 'nullable|string',
'contact_email' => 'nullable|string',
]);
$supplier = new Supplier($supplierData);
$supplier->save();
return response()->json($supplier);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Supplier $supplier): JsonResponse
{
$supplierData = $request->validate([
'name' => 'required|string',
'registration_name' => 'nullable|string',
'email' => 'nullable|email',
'address' => 'nullable|string',
'city' => 'nullable|string',
'zip' => 'nullable|string',
'country_code' => 'nullable|string',
'tax_fc' => 'nullable|string',
'tax_vat' => 'nullable|string',
'contact_name' => 'nullable|string',
'contact_phone' => 'nullable|string',
'contact_email' => 'nullable|string',
]);
$supplier->update($supplierData);
return response()->json($supplier);
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Http\Controllers;
use App\Models\Supplier;
class SupplierController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
return view('supplier.index');
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('supplier.create');
}
/**
* Display the specified resource.
*/
public function show(Supplier $supplier)
{
return view('supplier.show', ['supplier' => $supplier]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Supplier $supplier)
{
return view('supplier.edit', ['supplier' => $supplier]);
}
}