CustomerLogsController.php 2.3 KB

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