public function customModelItemAction($modelName, $id = null)
    {
        $config        = app('itemconfig');
        $actionFactory = app('admin_action_factory');
        $model         = $config->getDataModel();
        $model         = $model::find($id);
        $actionName    = $this->request->input('action_name', false);

        //get the action and perform the custom action
        $action = $actionFactory->getByName($actionName);
        $result = $action->perform($model);

        //override the config options so that we can get the latest
        app('admin_config_factory')->updateConfigOptions();

        //if the result is a string, return that as an error.
        if (is_string($result)) {
            return response()->json(array('success' => false, 'error' => $result));
        }
        //if it's falsy, return the standard error message
        elseif (!$result) {
            $messages = $action->getOption('messages');

            return response()->json(array('success' => false, 'error' => $messages['error']));
        } else {
            $fieldFactory  = app('admin_field_factory');
            $columnFactory = app('admin_column_factory');
            $fields        = $fieldFactory->getEditFields();
            $model         = $config->getModel($id, $fields, $columnFactory->getIncludedColumns($fields));

            if ($model->exists) {
                $model = $config->updateModel($model, $fieldFactory, $actionFactory);
            }

            $response = array('success' => true, 'data' => $model->toArray());

            //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');
            }
            //if it's a redirect, put the url into the redirect key so that javascript can transfer the user
            elseif (is_a($result, '\Illuminate\Http\RedirectResponse')) {
                $response['redirect'] = $result->getTargetUrl();
            }

            return response()->json($response);
        }
    }
public function customModelItemAction($modelName, $id = null)
    {
        $config        = app('itemconfig');
        $actionFactory = app('admin_action_factory');
        $model         = $config->getDataModel();
        $model         = $model::find($id);
        $actionName    = $this->request->input('action_name', false);

        //get the action and perform the custom action
        $action = $actionFactory->getByName($actionName);
        $result = $action->perform($model);

        //override the config options so that we can get the latest
        app('admin_config_factory')->updateConfigOptions();

        //if the result is a string, return that as an error.
        if (is_string($result)) {
            return response()->json(array('success' => false, 'error' => $result));
        }
        //if it's falsy, return the standard error message
        elseif (!$result) {
            $messages = $action->getOption('messages');

            return response()->json(array('success' => false, 'error' => $messages['error']));
        } else {
            $fieldFactory  = app('admin_field_factory');
            $columnFactory = app('admin_column_factory');
            $fields        = $fieldFactory->getEditFields();
            $model         = $config->getModel($id, $fields, $columnFactory->getIncludedColumns($fields));

            if ($model->exists) {
                $model = $config->updateModel($model, $fieldFactory, $actionFactory);
            }

            $response = array('success' => true, 'data' => $model->toArray());

            //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');
            }
            //if it's a redirect, put the url into the redirect key so that javascript can transfer the user
            elseif (is_a($result, '\Illuminate\Http\RedirectResponse')) {
                $response['redirect'] = $result->getTargetUrl();
            }

            return response()->json($response);
        }
    }
public function customModelItemAction ( $ modelName , $ id = null ) { $ config = app ( 'itemconfig' ) ; $ actionFactory = app ( 'admin_action_factory' ) ; $ model = $ config -> getDataModel ( ) ; $ model = $ model :: find ( $ id ) ; $ actionName = $ this -> request -> input ( 'action_name' , false ) ; //get the action and perform the custom action $ action = $ actionFactory -> getByName ( $ actionName ) ; $ result = $ action -> perform ( $ model ) ; //override the config options so that we can get the latest app ( 'admin_config_factory' ) -> updateConfigOptions ( ) ; //if the result is a string, return that as an error. if ( is_string ( $ result ) ) { return response ( ) -> json ( array ( 'success' => false , 'error' => $ result ) ) ; } //if it's falsy, return the standard error message elseif ( ! $ result ) { $ messages = $ action -> getOption ( 'messages' ) ; return response ( ) -> json ( array ( 'success' => false , 'error' => $ messages [ 'error' ] ) ) ; } else { $ fieldFactory = app ( 'admin_field_factory' ) ; $ columnFactory = app ( 'admin_column_factory' ) ; $ fields = $ fieldFactory -> getEditFields ( ) ; $ model = $ config -> getModel ( $ id , $ fields , $ columnFactory -> getIncludedColumns ( $ fields ) ) ; if ( $ model -> exists ) { $ model = $ config -> updateModel ( $ model , $ fieldFactory , $ actionFactory ) ; } $ response = array ( 'success' => true , 'data' => $ model -> toArray ( ) ) ; //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' ) ; } //if it's a redirect, put the url into the redirect key so that javascript can transfer the user elseif ( is_a ( $ result , '\Illuminate\Http\RedirectResponse' ) ) { $ response [ 'redirect' ] = $ result -> getTargetUrl ( ) ; } return response ( ) -> json ( $ response ) ; } }
POST method for handling custom model item actions.

@param string $modelName
@param int    $id

@return JSON
POST method for handling custom model item actions .