@param         $model_name
@param Request $request

@return \Illuminate\Http\JsonResponse
359192
public function getAllModels($model_name, Request $request)
    {
        $this->model_name = substr($model_name, 0, -1);

        return $this->getSomeModels($request, $request, 500);
    }
1304139
protected function buildDataTablesResponse(Request $request, $name, ActionResponse $output) {

        if (true === $request->isXmlHttpRequest()) {
            return new JsonResponse($output);
        }

        // Notify the user.
        switch ($output->getStatus()) {

            case 200:
                $this->notifySuccess($output->getNotify());
                break;

            case 404:
                $this->notifyDanger($output->getNotify());
                break;

            case 500:
                $this->notifyWarning($output->getNotify());
                break;
        }

        return $this->redirectToRoute("jquery_datatables_index", ["name" => $name]);
    }
1216654
public function deleteModel($model_name, $id, Request $request)
    {
        $this->checkParams(func_get_args());
        $status = $request->ajax() ? 202 : 200;

        $model = $this->findModel($model_name, $id);
        if (empty($model->id)) {
            if ($model = $model::withTrashed()->whereId($id)->first()) {
                $relations = config('kregel.warden.models.'.$model_name.'.relations');
                foreach ($relations as $rel) {
                    $model->$rel()->forceDelete();

                    $update_event = config('kregel.warden.models.'.$model_name.'.relations.'.$rel.'.delete');
                    if ($update_event instanceof Closure) {
                        $update_event($model);
                    }
                }
                $model->forceDelete();

                return response()->json(['message' => 'Resource deleted from the system.', 'code' => $status], $status);
            }

            return response()->json(['message' => 'No resource found!', 'code' => 404], 404);
        }
        $model->delete();
        if ($request->has('_redirect')) {
            // Remove the base part of the url, and just grab the tail end of the desired redirect, that way the
            // User can't be redirected away from your website.
            return $this->returnRedirect('Successfully updated resource', $request);
        }

        return response()->json(['message' => 'Successfully deleted resource', 'code' => $status], $status);
    }
1172745
public function findModel($model_name, $id = null)
    {
        $model = config('kregel.warden.models.'.$model_name.'.model');
        if (empty($id) | !is_numeric($id)) {
            return new $model();
        }

        return $model::find($id);
    }
465260
public function updateOrCreateRelations(Request $request, Model $model)
    {
        $parameterBag = $request->request;
        foreach ($parameterBag->all() as $name => $attributes) {
            if (is_array($request->{$name})) {
                $this->_checkRelationExists($model, $name);

                $relation = $model->{$name}();
                $this->handleRelations($attributes, $model, $relation);
            }
        }
    }
1135154
public function dependentSelect(Request $request, ModelConfigurationInterface $model, $field, $id = null)
    {
        $form = $this->getModelLogic($model, $id);

        if ($form instanceof JsonResponse) {
            return $form;
        }

        /** @var DependentSelect $element */
        $element = $form->getElement($field);

        if (is_null($element)) {
            return new JsonResponse([
                'message' => 'Element not found',
            ], 404);
        }

        $element->setAjaxParameters(
            $request->input('depdrop_all_params', [])
        );

        $options = $element->getOptions();

        if ($element->isNullable()) {
            $options = [null => trans('sleeping_owl::lang.select.nothing')] + $options;
        }

        return new JsonResponse([
            'output'   => collect($options)->map(function ($value, $key) {
                return ['id' => $key, 'name' => $value];
            }),
            'selected' => $element->getValueFromModel(),
        ]);
    }
831044
public function rename(Request $request, $bas_id)
    {
        if (trim($name = $request->request->get('name')) === '') {
            $this->app->abort(400, $this->app->trans('Missing name parameter'));
        }

        $success = false;

        $collection = \collection::getByBaseId($this->app, $bas_id);

        try {
            $collection->set_name($name);
            $success = true;
        } catch (\Exception $e) {

        }

        if ('json' === $this->app['request']->getRequestFormat()) {
            return $this->app->json([
                'success' => $success,
                'msg'     => $success ? $this->app->trans('Successful update') : $this->app->trans('An error occured'),
            ]);
        }

        return $this->app->redirectPath('admin_display_collection', [
            'bas_id'      => $collection->get_base_id(),
            'success'     => (int) $success,
            'reload-tree' => 1,
        ]);
    }
524700
private function modelVision(Model $model, $where, $value, $name, $querymap = null) : Model
  {
    if (strpos($where, '__') !== false) {
      $querymap = explode('__', $where)[1];
      $field = explode('__', $where)[0];
    }

    if (isset(HttpFoundation::$routeModelBinding['model'][$querymap])) {
      return (new HttpFoundation::$routeModelBinding['model'][$querymap])->persist($model, $field, $value, $name);
    }

    return $model->where($where, $value)->first() ?? $model;
  }
1247765
public function handlePostDefault(Request $request, $model)
    {
        $values = $this->parseRequestContent($request->content, $model->getResourceType());
        $this->validateModelData($model, $values);

        $model->fill($values);

        if (!$model->save()) {
            throw new Exception(
                'An unknown error occurred',
                static::ERROR_SCOPE | static::ERROR_UNKNOWN,
                BaseResponse::HTTP_INTERNAL_SERVER_ERROR
            );
        }

        return $model;
    }
1319213
public function run(&$query, $model, $request)
    {
        $this->query = $query;
        $this->getAttributes($model);
        $this->parseRequest($request);

        return $this->query();
    }
375446
public function byUsernameAction(Request $request)
   {
       $term = $request->get('username');
       $users = $this->get('asf_user.user.manager')->getRepository()->findByUsernameContains($term);
       $search = array();
       	
       foreach($users as $user) {
           $search[] = array(
               'id' => $user->getId(),
               'username' => $user->getUsername(),
               'email' => $user->getEmail()
           );
       }
       
       $response = new Response();
       $response->setContent(json_encode(array(
           'total_count' => count($search),
           'items' => $search
       )));
       
       return $response;
   }
1020295
public function signInWithProvider($provider_name, Request $request)
    {
        $provider = $this->getProvider($provider_name, $request);

        if (!$provider) {
            return $this->response(['errors' => [
                'code'    => 'PROVIDER_NOT_FOUND',
                'message' => 'No provider found',
            ]], Response::HTTP_BAD_REQUEST);
        }

        $provider->stateless();

        if ($request->input('code') !== null) {
            try {
                return $this->authenticateByCode($provider, $request->input('code'));
            } catch (\Exception $e) {
                return $this->response([
                    'code'    => 'CODE_NOT_VALID',
                    'message' => 'Code invalid or expired'.$e->getMessage(),
                ], Response::HTTP_BAD_REQUEST);
            }
        }
    }
433567
public function results($modelName)
    {
        $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());

        //return the rows
        return response()->json($dataTable->getRows(app('db'), $filters, $page, $sortOptions));
    }
349455
public function create(Request $request)
    {
        if ($request->wantsJson()) {
            return $this->validNotFoundJsonResponse();
        }

        $model = new $this->repository->model;

        $view = $this->getViewLocation(__FUNCTION__);
        $this->checkViewExists($view);

        return response()->view($view, compact('model'));
    }
1180300
public function create($model, Request $request)
    {
        $settings = json_decode($request->controller_settings);
        $fields = json_decode($request->fields, true);

        //dd($request->all());

        $path = $this->getpath($this->name);

        if ($this->files->exists($path)) {
            throw new \Exception("Controller [$this->name] already exists!");
        }

        $stub = $this->files->get($this->getStub());

        $stub = $this->replace($stub, $this->name, $model)
                        ->replaceDisableds($stub, $settings)
                        ->replaceTimestamps($stub, $settings)
                        ->replaceGrid($stub, $fields)
                        ->replaceForm($stub, $fields)
                        ->replaceHeader($stub, $settings);

        //dd($settings, $stub);

        $this->createMenu($settings);

        $this->createRout($settings);

        $this->files->put($path, $stub);

        return $path;
    }
533510
public function store(Request $request)
    {
        // Instantiate a new model item.
        $modelClass = $this->getModelClass();
        $item = new $modelClass;

        // Validate the request.
        $this->validate($request, $item->getValidationRules());

        // Create the new item.
        $itemData = $request->all();
        $item->fill($itemData);
        $item->save();

        $newItem = call_user_func([$this->getModelClass(), 'find'], $item->id)->toArray();
        return $this->generateResponse($this->modelTableName, $newItem);
    }
294836
protected function deleteModel($model_name, $id)
    {
        /*
         * Retrieve the desired model
         */
        $response = $this->delete('warden::api.delete-model', [$model_name, $id]);

        Session::flash('message', 'Hooray! It worked! The model was deleted!');

        return redirect(route('warden::models', $model_name));
    }