FrozenNode / Laravel-Administrator

An administrative interface package for Laravel
http://administrator.frozennode.com/
MIT License
1.94k stars 502 forks source link

Exception 'BadMethodCallException' with message 'Call to undefined method Illuminate\Database\Query\Builder:: #684

Closed jmichaelterenin closed 10 years ago

jmichaelterenin commented 10 years ago

I'm trying to make use of Laravel 4 Administrator's Global Actions ('global_actions' array) in the config for one of my tables, and regardless of what method I call, I get the dreaded:

local.ERROR: exception 'BadMethodCallException' with message 'Call to undefined method Illuminate\Database\Query\Builder::doNothing()' in C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:2117 Stack trace:

0 [internal function]: Illuminate\Database\Query\Builder->__call('doNothing', Array)

1 [internal function]: Illuminate\Database\Query\Builder->doNothing()

2 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php(913): call_user_func_array(Array, Array)

3 C:\xampp\htdocs\tikitour\app\config\administrator\countries.php(81): Illuminate\Database\Eloquent\Builder->__call('doNothing', Array)

4 C:\xampp\htdocs\tikitour\app\config\administrator\countries.php(81): Illuminate\Database\Eloquent\Builder->doNothing()

5 C:\xampp\htdocs\tikitour\vendor\frozennode\administrator\src\Frozennode\Administrator\Actions\Action.php(159): Frozennode\Administrator\Config\Factory->{closure}(Object(Illuminate\Database\Eloquent\Builder))

6 C:\xampp\htdocs\tikitour\vendor\frozennode\administrator\src\controllers\AdminController.php(205): Frozennode\Administrator\Actions\Action->perform(Object(Illuminate\Database\Eloquent\Builder))

7 [internal function]: Frozennode\Administrator\AdminController->customModelAction('Countries')

8 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(231): call_user_func_array(Array, Array)

9 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('customModelActi...', Array)

10 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(62): Illuminate\Routing\ControllerDispatcher->call(Object(Frozennode\Administrator\AdminController), Object(Illuminate\Routing\Route), 'customModelActi...')

11 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Routing\Router.php(962): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'Frozennode\Admi...', 'customModelActi...')

12 [internal function]: Illuminate\Routing\Router->Illuminate\Routing{closure}('Countries')

13 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Routing\Route.php(109): call_user_func_array(Object(Closure), Array)

14 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Routing\Router.php(1028): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))

15 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Routing\Router.php(996): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))

16 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(776): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))

17 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(746): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))

18 C:\xampp\htdocs\tikitour\vendor\barryvdh\laravel-debugbar\src\Middleware.php(34): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)

19 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Session\Middleware.php(72): Barryvdh\Debugbar\Middleware->handle(Object(Illuminate\Http\Request), 1, true)

20 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Cookie\Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)

21 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Cookie\Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)

22 C:\xampp\htdocs\tikitour\vendor\stack\builder\src\Stack\StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)

23 C:\xampp\htdocs\tikitour\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(642): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))

24 C:\xampp\htdocs\tikitour\public\index.php(49): Illuminate\Foundation\Application->run()

25 {main} [] []

The config array is below, the 'permission' property works just fine, and I now have it so the doNothing() method just returns true:

'global_actions' => array( //Importing data via xls upload 'use_upload' => array( 'title' => 'Use Upload', 'messages' => array( 'active' => 'Uploading...', 'success' => 'Uploaded', 'error' => 'There was an error while Uploading', ), 'permission' => function($model) {
return $model->hasUpload();
}, //the model is passed to the closure 'action' => function($model) {

            $model->doNothing();                               
        }
    ),

),      

Most importantly, this works perfect outside of administrator. It would seem like the methods of the model have to be somehow registered with Illuminate, but I don't think that's the case since ->hasUpload() is recognized and works fine.

jmichaelterenin commented 10 years ago

Resolved: global_action passes Illuminate's query Builder object into the action, so I just instantiated the copy of the model I'm working with