You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
topnotch_website/app/Http/Controllers/CustomerController.php

69 lines
2.2 KiB
PHTML

3 months ago
<?php
namespace App\Http\Controllers;
use App\Http\Requests\CustomerRequest;
use App\Models\Customer;
3 months ago
use App\Models\PackingSlip;
2 months ago
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application;
use Illuminate\Http\RedirectResponse;
3 months ago
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
3 months ago
class CustomerController extends Controller
{
2 months ago
public function index(): void {}
3 months ago
public function store(CustomerRequest $request)
{
3 months ago
Customer::create($request->validated());
3 months ago
3 months ago
return redirect()->route('management.index')->with('status', 'Customer created successfully.');
3 months ago
}
2 months ago
public function create(): Factory|View|Application|\Illuminate\View\View
3 months ago
{
3 months ago
return view('customers.create');
3 months ago
}
2 months ago
public function show(Customer $customer, ?string $tab = null): RedirectResponse|View
3 months ago
{
3 months ago
if (! $tab) {
3 months ago
return redirect()->route('customers.show', [$customer, 'tab' => 'details']);
}
return view('customers.show', [
3 months ago
'tab' => $tab,
'customer' => $customer,
'contacts' => $customer->contacts()->get(),
'packingSlips' => PackingSlip::where('customer_id', $customer->id)->orderByDesc('date_received')->paginate(15),
3 months ago
'shippingEntries' => $customer->shippingEntries()->get(),
3 months ago
'today' => Carbon::today()->format('Y-m-d'),
3 months ago
]);
3 months ago
}
2 months ago
public function update(CustomerRequest $request, Customer $customer): RedirectResponse
3 months ago
{
3 months ago
$customer->update($request->validated());
return redirect()->route('customers.show', $customer)->with('status', 'Customer updated successfully.');
}
2 months ago
public function requestDestroy(Request $request): RedirectResponse
3 months ago
{
$customer = Customer::find($request->id);
$customer->delete();
3 months ago
3 months ago
return redirect()->route('management.index')->with('status', 'Customer deleted successfully.');
3 months ago
}
2 months ago
public function destroy(Customer $customer): RedirectResponse
3 months ago
{
3 months ago
$customer->delete();
3 months ago
3 months ago
return redirect()->route('management.index')->with('status', 'Customer deleted successfully.');
3 months ago
}
}