| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Http\Controllers;
- use App\Customer;
- use App\CustomerLog;
- use App\CustomerLogStatus;
- use Illuminate\Http\RedirectResponse;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- class CustomerLogsController extends Controller
- {
- public function __construct()
- {
- $this->middleware('auth', ['except' => ['index', 'show']]);
- }
- public function index()
- {
- $customer_logs = CustomerLog::query()->with(['customerLogStatus', 'user', 'customer'])->orderByDesc('updated_at')->paginate();
- return view('customer_logs.index', compact('customer_logs'));
- }
- public function show($customer_log_id)
- {
- $customer_log =CustomerLog::query()->with(['customerLogStatus', 'user', 'customer'])->where('id',$customer_log_id)->first();
- return view('customer_logs.show', compact('customer_log'));
- }
- public function create(CustomerLog $customer_log)
- {
- $customers = Customer::all();
- $customerLogStatuses = CustomerLogStatus::all();
- return view('customer_logs.create_and_edit', compact('customer_log', 'customers', 'customerLogStatuses'));
- }
- public function store(Request $request): RedirectResponse
- {
- $data = [];
- $data = $request->all();
- $data['user_id'] = auth()->id();
- $customer_log = CustomerLog::create($data);
- return redirect()->route('customer_logs.show', $customer_log->id)->with('message', 'Created successfully.');
- }
- public function edit(CustomerLog $customer_log)
- {
- $this->authorize('update', $customer_log);
- $customers = Customer::all();
- $customerLogStatuses = CustomerLogStatus::all();
- return view('customer_logs.create_and_edit', compact('customer_log', 'customers', 'customerLogStatuses'));
- }
- public function update(Request $request, CustomerLog $customer_log)
- {
- $this->authorize('update', $customer_log);
- $customer_log->update($request->all());
- return redirect()->route('customer_logs.show', $customer_log->id)->with('message', 'Updated successfully.');
- }
- public function destroy(CustomerLog $customer_log)
- {
- $this->authorize('destroy', $customer_log);
- $customer_log->delete();
- return redirect()->route('customer_logs.index')->with('message', 'Deleted successfully.');
- }
- }
|