📜 ⬆️ ⬇️

Package to create admin in projects on Laravel

What do you think is the worst and most boring stage in creating a website in PHP? In my opinion - this is the creation of the admin. All these uniform forms, tables, a large number of almost identical files that need to not only be created, but subsequently maintained. Therefore, under each framework I used, sooner or later, I created a set of classes that facilitate this process.

And so I got to Laravel. I present to you a package that will help you quickly create an admin panel and devote more time to the frontend.

You ask, what in my “bicycle” made me publish it for all to see? For me, these are his several strengths:

In-zero , he helps me in real projects. Perhaps it will help someone else, and this already means that everything was not done in vain.
')
First , the configuration files.

I am tired of configs, which are a magically created array in which there are keys with certain names and textual meanings of these keys. No help from IDE with auto substitution or highlighting of incorrectly specified values ​​found in the project code where a specific key from the config is specifically processed and what it does is far from a trivial task. And besides, the package code you have here is a weak assistant, the documentation is your only friend.

Therefore, I abandoned configs in the form of arrays (php arrays, yaml files, it does not matter) and came to the config files in the form of php code. Here is a small example of the description of the “Country” model from the demo application for use in the admin panel.

Admin::model('\Country')->title('Countries')->with('contacts')->columns(function () { Column::string('title', 'Title'); Column::count('contacts', 'Contacts')->append(Column::filter('country_id')->model('\Contact')); })->form(function () { FormItem::text('title', 'Title'); }); 


I do not know about you, but it seems to me that it is much more readable than an array with keys, although in fact it contains all the same information.

Several advantages of this approach:


Secondly , extensibility.

You can register your own types of columns and form elements that will later be used in your models. Therefore, you are not limited solely to the functionality that I created.

You can also register your own controllers for processing certain menu items - and here you are no longer limited.

Thirdly , the amount of work that must be done to create the admin.

You will need to create a menu, as well as create a description of each model for which you want to create an admin panel. And it's all.

I created this package for use mainly in small projects that have many weakly interconnected models. As a rule, their main goal is to display data in the frontend in accordance with the design, and what kind of admin there will be is not so important to the customer, if only to fulfill the main goal - to manage the content of the site.

sources on github | project documentation | demo application

Source: https://habr.com/ru/post/240809/


All Articles