SchedulingController.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Encore\Admin\Scheduling;
  3. use Encore\Admin\Facades\Admin;
  4. use Encore\Admin\Layout\Content;
  5. use Illuminate\Http\Request;
  6. class SchedulingController
  7. {
  8. /**
  9. * Index interface.
  10. *
  11. * @return Content
  12. */
  13. public function index()
  14. {
  15. return Admin::content(function (Content $content) {
  16. $content->header('Task scheduling');
  17. $scheduling = new Scheduling();
  18. $content->body(view('laravel-admin-scheduling::index', [
  19. 'events' => $scheduling->getTasks(),
  20. ]));
  21. });
  22. }
  23. /**
  24. * @param Request $request
  25. *
  26. * @return array
  27. */
  28. public function runEvent(Request $request)
  29. {
  30. $scheduling = new Scheduling();
  31. try {
  32. $output = $scheduling->runTask($request->get('id'));
  33. return [
  34. 'status' => true,
  35. 'message' => 'success',
  36. 'data' => $output,
  37. ];
  38. } catch (\Exception $e) {
  39. return [
  40. 'status' => false,
  41. 'message' => 'failed',
  42. 'data' => $e->getMessage(),
  43. ];
  44. }
  45. }
  46. }