{"action":"closed","issue":{"url":"https://api.github.com/repos/Laravel-Backpack/CRUD/issues/207","repository_url":"https://api.github.com/repos/Laravel-Backpack/CRUD","labels_url":"https://api.github.com/repos/Laravel-Backpack/CRUD/issues/207/labels{/name}","comments_url":"https://api.github.com/repos/Laravel-Backpack/CRUD/issues/207/comments","events_url":"https://api.github.com/repos/Laravel-Backpack/CRUD/issues/207/events","html_url":"https://github.com/Laravel-Backpack/CRUD/issues/207","id":185565650,"number":207,"title":"enableAjaxTable gives Undefined variable: entry","user":{"login":"mpixelz","id":22141147,"avatar_url":"https://avatars.githubusercontent.com/u/22141147?v=3","gravatar_id":"","url":"https://api.github.com/users/mpixelz","html_url":"https://github.com/mpixelz","followers_url":"https://api.github.com/users/mpixelz/followers","following_url":"https://api.github.com/users/mpixelz/following{/other_user}","gists_url":"https://api.github.com/users/mpixelz/gists{/gist_id}","starred_url":"https://api.github.com/users/mpixelz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpixelz/subscriptions","organizations_url":"https://api.github.com/users/mpixelz/orgs","repos_url":"https://api.github.com/users/mpixelz/repos","events_url":"https://api.github.com/users/mpixelz/events{/privacy}","received_events_url":"https://api.github.com/users/mpixelz/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-27T03:34:58Z","updated_at":"2016-10-27T04:18:58Z","closed_at":"2016-10-27T04:18:58Z","body":"Hi,\r\ni have backpack crud controller.. im using one controller to divide the user list depending on their status..\r\nhere is my controller:\r\n```\r\n<?php namespace App\\Http\\Controllers\\Admin;\r\n\r\nuse Backpack\\CRUD\\app\\Http\\Controllers\\CrudController;\r\nuse validator;\r\nuse Illuminate\\Http\\Request;\r\nuse Spatie\\Permission\\Traits\\HasRoles;\r\nuse App\\User;\r\n// VALIDATION: change the requests to match your own file names if you need form validation\r\nuse App\\Http\\Requests\\StudentListsRequest as StoreRequest;\r\nuse App\\Http\\Requests\\StudentListsRequest as UpdateRequest;\r\n\r\nclass StudentListsCrudController extends CrudController {\r\nuse HasRoles;\r\n\tpublic function __construct() {\r\n        parent::__construct();\r\n\r\n        $this->crud->setModel(\"App\\Models\\StudentLists\");\r\n        $this->crud->setRoute(\"admin/student-list\");\r\n        $this->crud->setEntityNameStrings('New Student', 'Student List');\r\n        // $this->crud->enableAjaxTable();\r\n        $this->crud->enableExportButtons();\r\n\r\n\t\t$this->crud->setFromDb();\r\n        $this->crud->addField([\r\n                            'name' => 'password_confirmation',\r\n                            'label' => 'Password Confirmation',\r\n                            'type' => 'password',\r\n                            ]);\r\n    $this->crud->setModel(\"App\\User\");\r\n        $this->crud->addColumn([ // n-n relationship (with pivot table)\r\n       'label' => \"Roles\", // Table column heading\r\n       'type' => \"select_multiple\",\r\n       'name' => 'roles', // the method that defines the relationship in your Model\r\n       'entity' => 'roles', // the method that defines the relationship in your Model\r\n       'attribute' => \"name\", // foreign key attribute that is shown to user\r\n       'model' => \"Backpack\\PermissionManager\\app\\Models\\Roles\", // foreign key model\r\n        ]);\r\n        $this->crud->removeColumns(['password', 'roles', 'assign_user']); // remove an array of columns from the stack\r\n        $this->crud->addClause('whereHas', 'roles', function($query) {\r\n            $query->where('name', 'Student');\r\n        });\r\n    }\r\n\r\n    public function index()\r\n    {\r\n    $this->crud->hasAccessOrFail('list');\r\n    $this->data['crud'] = $this->crud;\r\n    $this->data['title'] = ucfirst($this->crud->entity_name_plural);\r\n    $userallocation = User::all()->filter(function (User $user) { return $user->hasPermissionTo('user_allocation'); });\r\n    // get all entries if AJAX is not enabled\r\n    if (! $this->data['crud']->ajaxTable()) {\r\n        $this->data['entries'] = $this->data['crud']->getEntries();\r\n    }\r\n    return view('StudentLists', $this->data)\r\n    ->with('userallocation', $userallocation);\r\n    }\r\n\r\n    public function prospective()\r\n    {\r\n    $this->crud->setEntityNameStrings('New Student', 'Student List - Prospective');\r\n    $this->crud->hasAccessOrFail('list');\r\n\r\n    $this->data['crud'] = $this->crud;\r\n    $this->data['title'] = ucfirst($this->crud->entity_name_plural);\r\n    $userallocation = User::all()->filter(function (User $user) { return $user->hasPermissionTo('user_allocation'); });\r\n    // // get all entries if AJAX is not enabled\r\n    if (! $this->data['crud']->ajaxTable()) {\r\n        $this->data['entries'] = $this->data['crud']->getEntries()->where('registrationstep', null);\r\n    }\r\n    return view('StudentLists', $this->data)\r\n    ->with('userallocation', $userallocation)\r\n    ;\r\n    }\r\n\r\n    public function leads()\r\n    {\r\n    $this->crud->hasAccessOrFail('list');\r\n    $this->data['crud'] = $this->crud;\r\n    $this->data['title'] = ucfirst($this->crud->entity_name_plural);\r\n    $this->crud->removeButton('create');\r\n    \r\n\r\n    $userallocation = User::all()->filter(function (User $user) { return $user->hasPermissionTo('user_allocation'); });\r\n\r\n    $this->crud->addColumn([\r\n   'name' => 'assign_user', // The db column name\r\n   'label' => 'Assigned User', // Table column heading\r\n    ]);\r\n    $this->crud->addColumn([\r\n   // run a function on the CRUD model and show its return value\r\n   'label' => \"Assign User\", // Table column heading\r\n   'type' => \"model_function\",\r\n   'function_name' => 'assignauser', // the method in your Model\r\n    ]);\r\n\r\n    // get all entries if AJAX is not enabled\r\n    if (! $this->data['crud']->ajaxTable()) {\r\n        $this->data['entries'] = $this->data['crud']->getEntries()->where('registrationstep', 1);\r\n    }\r\n    return view('StudentLists', $this->data)\r\n    ->with('userallocation', $userallocation)\r\n    ;\r\n    }\r\n\r\n    public function assigneduser(Request $request)\r\n    {\r\n        $user_id = $request->id;\r\n        $user = User::firstOrNew(['id' => $user_id]);\r\n        $formdata = $request->all();\r\n        $user->update($formdata);\r\n        return \\Redirect::back();\r\n    }\r\n\r\n    public function create()\r\n    {\r\n        $this->crud->hasAccessOrFail('create');\r\n        // prepare the fields you need to show\r\n        $this->data['crud'] = $this->crud;\r\n        $this->data['fields'] = $this->crud->getCreateFields();\r\n        $this->data['title'] = trans('backpack::crud.add').' '.$this->crud->entity_name;\r\n       \r\n        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package\r\n        return view('crud::create', $this->data);\r\n    }\r\n\tpublic function store(StoreRequest $request)\r\n\t{\r\n        // insert item in the db\r\n        if ($request->input('password')) {\r\n            $item = $this->crud->create(\\Request::except(['redirect_after_save']))->assignRole('Student');\r\n            // now bcrypt the password\r\n            $item->password = bcrypt($request->input('password'));\r\n            $item->save();\r\n        } else {\r\n            $item = $this->crud->create(\\Request::except(['redirect_after_save', 'password']));\r\n        }\r\n\r\n        // show a success message\r\n        \\Alert::success(trans('backpack::crud.insert_success'))->flash();\r\n        // redirect the user where he chose to be redirected\r\n        switch (\\Request::input('redirect_after_save')) {\r\n            case 'current_item_edit':\r\n                return \\Redirect::to($this->crud->route.'/'.$item->id.'/edit');\r\n            default:\r\n                return \\Redirect::to(\\Request::input('redirect_after_save'));\r\n        }\r\n\t\t//return parent::storeCrud();\r\n\t}\r\n\r\n\tpublic function update(UpdateRequest $request)\r\n\t{\r\n\t\treturn parent::updateCrud();\r\n\t}\r\n}\r\n```\r\n\r\nusing the above controller (not using ajax table) it works but only if there are any records in that table.. \r\nand if i enable the ajaxtable it gives me:\r\n`Undefined variable: entry`\r\n\r\neven if i disable the ajaxtable and if there are no records meeting the criteria i still get the same error..\r\ncan anyone point out what am i doing wrong here? :("}}
{"actor":{"display_login":"mpixelz"}}