moved ajax dispatch to trait

This commit is contained in:
denisdulici 2020-03-09 10:26:02 +03:00
parent b243b3f750
commit 58a796c2b4
2 changed files with 30 additions and 30 deletions

View File

@ -30,7 +30,7 @@ abstract class Controller extends BaseController
*
* @return void
*/
protected function setPermissions()
public function setPermissions()
{
// No need to check for permission in console
if (app()->runningInConsole()) {
@ -90,33 +90,4 @@ abstract class Controller extends BaseController
return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options);
}
/**
* Dispatch a job to its appropriate handler and return a response array for ajax calls.
*
* @param mixed $job
* @return mixed
*/
public function ajaxDispatch($job)
{
try {
$data = $this->dispatch($job);
$response = [
'success' => true,
'error' => false,
'data' => $data,
'message' => '',
];
} catch(\Exception $e) {
$response = [
'success' => false,
'error' => true,
'data' => null,
'message' => $e->getMessage(),
];
}
return $response;
}
}

View File

@ -31,6 +31,35 @@ trait Jobs
return $result;
}
/**
* Dispatch a job to its appropriate handler and return a response array for ajax calls.
*
* @param mixed $job
* @return mixed
*/
public function ajaxDispatch($job)
{
try {
$data = $this->dispatch($job);
$response = [
'success' => true,
'error' => false,
'data' => $data,
'message' => '',
];
} catch(\Exception $e) {
$response = [
'success' => false,
'error' => true,
'data' => null,
'message' => $e->getMessage(),
];
}
return $response;
}
public function getDispatchFunction()
{
$config = config('queue.default');