[mostly code] musings of a software developer from nairobi 🇰🇪 | learning
Register Custom Doctrine Column Type Mappings for Laravel Backpack CRUD
January 2, 2017
I’ve been using Laravel Backpack CRUD to build the backend for a personal application, and I must say - great tool! Generation of the CRUD part of the application is only an artisan command away! Reminds me of the Yii Auto generator.
However, I run into an issue with one of my database columns that has type JSON. After running the backpack:crud command, the UI for it wasn’t loading. Instead the error below was showing:
Upon doing some research (read extensive Googling/Github Issue checking), it turns out it’s a DBAL-related issue, affecting specific column types in MySQL (including enum & json-like columns).
Implementing a modified version of the CrudController, which;
Implements a modified CrudPanel class that includes addition of the custom column types mentioned in the fix
First, create a directory called CRUD under the app directory of your Laravel application (you can call it anything you please, be sure to update the code below to match your naming), then create a new PHP file there which will have the modified CrudPanel class:
Next, create a custom CrudController file which will have our extended & modified CrudController class. I put mine in app/Http/Controllers/Admin/ - where the other Backpack CRUD controllers are.
Put the code below in CustomCrudPanel.php:
Put the code below in CustomCrudController.php:
Finally, in your auto-generated CrudController class for the model with an enum or json column, update it to extend the CustomCrudController class instead.
E.g. if the CrudController class with the json column is called PlaylistCrudController, it should look something like:
If all goes well, you should be able to view the CRUD for our troublesome model.