CustomerLogsController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Customer;
  4. use App\CustomerLog;
  5. use App\CustomerLogStatus;
  6. use Illuminate\Http\RedirectResponse;
  7. use Illuminate\Http\Request;
  8. use App\Http\Controllers\Controller;
  9. class CustomerLogsController extends Controller
  10. {
  11. public function __construct()
  12. {
  13. $this->middleware('auth', ['except' => ['index', 'show']]);
  14. }
  15. public function index()
  16. {
  17. $customer_logs = CustomerLog::query()->with(['customerLogStatus', 'user', 'customer'])->orderByDesc('updated_at')->paginate();
  18. return view('customer_logs.index', compact('customer_logs'));
  19. }
  20. public function show($customer_log_id)
  21. {
  22. $customer_log =CustomerLog::query()->with(['customerLogStatus', 'user', 'customer'])->where('id',$customer_log_id)->first();
  23. return view('customer_logs.show', compact('customer_log'));
  24. }
  25. public function create(CustomerLog $customer_log)
  26. {
  27. $customers = Customer::all();
  28. $customerLogStatuses = CustomerLogStatus::all();
  29. return view('customer_logs.create_and_edit', compact('customer_log', 'customers', 'customerLogStatuses'));
  30. }
  31. public function store(Request $request): RedirectResponse
  32. {
  33. $data = [];
  34. $data = $request->all();
  35. $data['user_id'] = auth()->id();
  36. $customer_log = CustomerLog::create($data);
  37. return redirect()->route('customer_logs.show', $customer_log->id)->with('message', 'Created successfully.');
  38. }
  39. public function edit(CustomerLog $customer_log)
  40. {
  41. $this->authorize('update', $customer_log);
  42. $customers = Customer::all();
  43. $customerLogStatuses = CustomerLogStatus::all();
  44. return view('customer_logs.create_and_edit', compact('customer_log', 'customers', 'customerLogStatuses'));
  45. }
  46. public function update(Request $request, CustomerLog $customer_log)
  47. {
  48. $this->authorize('update', $customer_log);
  49. $customer_log->update($request->all());
  50. return redirect()->route('customer_logs.show', $customer_log->id)->with('message', 'Updated successfully.');
  51. }
  52. public function destroy(CustomerLog $customer_log)
  53. {
  54. $this->authorize('destroy', $customer_log);
  55. $customer_log->delete();
  56. return redirect()->route('customer_logs.index')->with('message', 'Deleted successfully.');
  57. }
  58. }