Check the stack trace in your storage/logs/{LOG FILE NAME}.
Where to start debugging
Hi guys,
I have a form with a submit button, When I try to submit data I get ( it's only a test site, so nothings gonna break! )
FatalThrowableError In ManagesTransactions.php line 109 :
Call to a member function beginTransaction() on null
I am trying to figure out where the error is occurring in the code. I have installed https://github.com/barryvdh/laravel-debugbar. How do I use it to help me find where the fault is? I see the bar at the bottom of the screen, but it has no errors. Can I get to connect to a path ie http://mysite.com/some-route/myform?
Should of thought of that, thanks!
Returns lots of stuff, but it looks like the error is here:
Route), Object(Encore\Admin\Controllers\MenuController), 'store')
Only trouble is The MenuController does not contain a function 'store'!! eek!
I'm guessing its this function that is at fault
public function form()
{
$menuModel = config('admin.database.menu_model');
$permissionModel = config('admin.database.permissions_model');
$roleModel = config('admin.database.roles_model');
$form = new Form(new $menuModel());
$form->display('id', 'ID');
$form->select('parent_id', trans('admin.parent_id'))->options($menuModel::selectOptions());
$form->text('title', trans('admin.title'))->rules('required');
$form->icon('icon', trans('admin.icon'))->default('fa-bars')->rules('required')->help($this->iconHelp());
$form->text('uri', trans('admin.uri'));
$form->multipleSelect('roles', trans('admin.roles'))->options($roleModel::all()->pluck('name', 'id'));
if ($form->model()->withPermission()) {
$form->select('permission', trans('admin.permission'))->options($permissionModel::pluck('name', 'slug'));
}
$form->display('created_at', trans('admin.created_at'));
$form->display('updated_at', trans('admin.updated_at'));
return $form;
}
How to use the bugbar to check the variables $menuModel , $permissionModel and $roleModel ?
I tried adding:
use DebugBar\StandardDebugBar;
Then just after this code I added:
public function form()
{
$menuModel = config('admin.database.menu_model');
$permissionModel = config('admin.database.permissions_model');
$roleModel = config('admin.database.roles_model');
Debugbar::info($menuModel); // code added by me!!!
Debugbar::info($permissionModel);
Debugbar::info($roleModel);
But nothing appears in the bugbar, am I using the correct approach?
Those things will only work if you actually hit that route. Is that happening?
You can check these in tinker.
Just open tinker and type config('admin.database.menu_model') etc
Ok, from tinker:
>>> config('admin.database.menu_model')
"Encore\Admin\Auth\Database\Menu"
Which is the menu_model for the MenuController code above, what now?
Come on guys, don't be shy, help me out!
Sorry - work.
You're not giving us much to go on?
An error occurs. What were you doing at the time?
That config contains a model name (as a string). How is that relevant ?
I don't have much to go on other than what I have posted above:
I go to any input page and when I hit submit i get:
FatalThrowableError In MenuController.php line 124 :
Class 'Encore\Admin\Controllers\Debugbar' not found
Looking in the logs tells me the error is in:
Route), Object(Encore\Admin\Controllers\MenuController), 'store')
Then looking in that file gives me:
public function form()
{
$menuModel = config('admin.database.menu_model');
$permissionModel = config('admin.database.permissions_model');
$roleModel = config('admin.database.roles_model');
$form = new Form(new $menuModel());
$form->display('id', 'ID');
$form->select('parent_id', trans('admin.parent_id'))->options($menuModel::selectOptions());
$form->text('title', trans('admin.title'))->rules('required');
$form->icon('icon', trans('admin.icon'))->default('fa-bars')->rules('required')->help($this->iconHelp());
$form->text('uri', trans('admin.uri'));
$form->multipleSelect('roles', trans('admin.roles'))->options($roleModel::all()->pluck('name', 'id'));
if ($form->model()->withPermission()) {
$form->select('permission', trans('admin.permission'))->options($permissionModel::pluck('name', 'slug'));
}
$form->display('created_at', trans('admin.created_at'));
$form->display('updated_at', trans('admin.updated_at'));
return $form;
}
usin tinker:
>>> config('admin.database.menu_model')
"Encore\Admin\Auth\Database\Menu"
Which is the menu_model for the MenuController code above, dunno what else to try?
Did you import (use) Debugbar at the top of that controller?
Sure did:
use DebugBar\StandardDebugBar;
Error say it can't find Encore\Admin\Controllers\Debugbar, you are not importing a class called Debugbar
Followed instructions here: https://github.com/barryvdh/laravel-debugbar#laravel-55
I don't get any error about importing the class???
use DebugBar\StandardDebugBar;
This resolves something called StandardDebugBar not Debugbar
use DebugBar\StandardDebugBar;
This resolves something called StandardDebugBar not Debugbar
How the heck am I supposed to use Debugbar ??
What I don't understand is why you are pulling Debugbar into a controller?
You just composer require it. That's all
From the laravel logs, it points to an error in Route), Object(Encore\Admin\Controllers\MenuController), 'store') That's why im trying to start debugging there. I have installed Debugbar with composer.
/**
* Make a form builder.
*
* @return Form
*/
public function form()
{
$menuModel = config('admin.database.menu_model');
$permissionModel = config('admin.database.permissions_model');
$roleModel = config('admin.database.roles_model');
Debugbar::info($menuModel); // code added by me!!!
Debugbar::info($permissionModel);
Debugbar::info($roleModel);
debug($menuModel, $permissionModel);
does nothing, What else can I try?
@ludo1960 Just dd the variables so you can see what kind of data they contain
dd($menuModel, $permissionModel, $roleModel);
Result of
dd($menuModel, $permissionModel, $roleModel)
is
"Encore\Admin\Auth\Database\Menu"
"Encore\Admin\Auth\Database\Permission"
"Encore\Admin\Auth\Database\Role"
@ludo1960 So it seems they return the correct results right?
You can use dd on other places as well, until you find the bug you're really looking for!
Thanks, i'll give it a go. Was hoping somebody knew how to get that darn Debugbar working!
The debuger only works whenever you give a response back. A fatal error cannot be caught by PHP, so that's the problem ;)
one step forward and two steps back! Any other useful functions other than dd?
-
check which route is being called in the network tools of your browser
-
check where that goes in your routes
-
insert
dd('here');at the top of the controller method you expect is hit -
try it
if you hit the dd work your way through the controller
(debugbar is a very useful tool but the framework has to complete the request cycle in order to see the results. If you want to use Debugbar::info type message then you need to install the facade)
!. route being called is admin/auth/roles/1
- routes has nothing about admin/auth/roles
use Illuminate\Routing\Router;
Admin::registerAuthRoutes();
Route::group([
'prefix' => config('admin.route.prefix'),
'namespace' => config('admin.route.namespace'),
'middleware' => config('admin.route.middleware'),
], function (Router $router) {
$router->get('/', 'HomeController@index');
});
- Insert dd in rolecontroller:
public function edit($id, Content $content)
{
dd($id);
return $content
->header(trans('admin.roles'))
->description(trans('admin.edit'))
->body($this->form()->edit($id));
}
ModelNotFoundException In Builder.php line 369 :
No query results for model [Encore\Admin\Auth\Database\Role] 1
```
dd displays nothing and lins 369 in Builder.php
```
public function getHiddenFields()
{
return $this->hiddenFields; // this is line 369
}
So its not going to the role controller edit function?
I'm guessing this is not your code base then?
Your latest error is totally different to the first. Are you in another part of the site?
The error you post now suggests that your database is not seeded correctly with roles
Gonna re-install and go back to the drawing board, happy days!
@ludo1960 You can use xdebug instead of dd :D
Got xdebug installed, php -v shows xdebug is installed. Got https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug installed. Now the small matter of getting vscode to talk to xdebug. I tried adding:
// server -> local
"pathMappings": {
"/var/www/mysite.com/public": "${workspaceRoot}/www",
"/app": "${workspaceRoot}/app"
}
But it didn't like it, can some please tell me what the have in their launch.json. Here's what I've got at the moment:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
Please or to participate in this conversation.