public function customModelAction($modelName)
{
$config = app('itemconfig');
$actionFactory = app('admin_action_factory');
$actionName = $this->request->input('action_name', false);
$dataTable = app('admin_datatable');
//get the sort options and filters
$page = $this->request->input('page', 1);
$sortOptions = $this->request->input('sortOptions', array());
$filters = $this->request->input('filters', array());
//get the prepared query options
$prepared = $dataTable->prepareQuery(app('db'), $page, $sortOptions, $filters);
//get the action and perform the custom action
$action = $actionFactory->getByName($actionName, true);
$result = $action->perform($prepared['query']);
//if the result is a string, return that as an error.
if (is_string($result)) {
return response()->json(array('success' => false, 'error' => $result));
} elseif (!$result) {
$messages = $action->getOption('messages');
return response()->json(array('success' => false, 'error' => $messages['error']));
} else {
$response = array('success' => true);
//if it's a download response, flash the response to the session and return the download link
if (is_a($result, 'Symfony\\Component\\HttpFoundation\\BinaryFileResponse')) {
$file = $result->getFile()->getRealPath();
$headers = $result->headers->all();
$this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers));
$response['download'] = route('admin_file_download');
} elseif (is_a($result, '\\Illuminate\\Http\\RedirectResponse')) {
$response['redirect'] = $result->getTargetUrl();
}
return response()->json($response);
}
}