Create routes and views for suppliers.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
41
app/Http/Controllers/SupplierController.php
Normal file
41
app/Http/Controllers/SupplierController.php
Normal 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]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Supplier extends Model
|
||||
{
|
||||
@@ -28,6 +27,22 @@ class Supplier extends Model
|
||||
'contact_email',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are appended with attribute getters.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $appends = [
|
||||
'created',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the issue_date attribute in local time format.
|
||||
*/
|
||||
public function getCreatedAttribute(): string
|
||||
{
|
||||
return $this->created_at->format('d.m.Y');
|
||||
}
|
||||
/**
|
||||
* Get the supplier's incoming invoices.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user