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

71 lines
2.0 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;
use App\Models\ShippingEntry;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
3 months ago
class CustomerController extends Controller
{
3 months ago
public function index(Request $request)
3 months ago
{
3 months ago
return view('customers.index', [
'customers' => Customer::all(),
'tab' => $request->tab,
]);
3 months ago
}
public function store(CustomerRequest $request)
{
3 months ago
Customer::create($request->validated());
3 months ago
3 months ago
return redirect()->route('customers.index')->with('status', 'Customer created successfully.');
3 months ago
}
public function create()
{
3 months ago
return view('customers.create');
3 months ago
}
3 months ago
public function show(Customer $customer, string $tab=null)
3 months ago
{
3 months ago
if (!$tab) {
return redirect()->route('customers.show', [$customer, 'tab' => 'details']);
}
return view('customers.show', [
'customer' => $customer,
'contacts' => $customer->contacts()->get(),
'packingSlips' => PackingSlip::where('customer_id', $customer->id)->orderByDesc('date_received')->paginate(15),
'tab' => $tab,
'today' => Carbon::today()->format('Y-m-d'),
'shippingEntries' => $customer->shippingEntries()->get(),
]);
3 months ago
}
public function update(CustomerRequest $request, Customer $customer)
{
3 months ago
$customer->update($request->validated());
3 months ago
3 months ago
return redirect()->route('customers.show', $customer)->with('status', 'Customer updated successfully.');
3 months ago
}
3 months ago
public function requestDestroy(Request $request)
{
$customer = Customer::find($request->id);
$customer->delete();
return redirect()->route('customers.index')->with('status', 'Customer deleted successfully.');
}
3 months ago
public function destroy(Customer $customer)
{
3 months ago
$customer->delete();
3 months ago
3 months ago
return redirect()->route('customers.index')->with('status', 'Customer deleted successfully.');
3 months ago
}
}