CustomerLogController.php 2.3 KB

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