Administration Panel with Laravel 5.4

Roberto Butti
3 min readMay 24, 2017

--

How to build an administration panel with Laravel 5

A common question about Laravel and, in general, about frameworks is: “How to built an administration panel?”. You can start from scratch by building dashboards, the listing, filters, sorting, pagination, form etc or by using a sort of tool that helps you to build this feature in the fastest way, starting from models (entities) and/or a configuration file.

In the past (Laravel4) I used FrozenNode for several projects (https://github.com/FrozenNode/Laravel-Administrator).

Today the original FrozenNode is not maintained anymore.

But don’t worry, a great guy (my friend) forked the original project and updated the project to support also Laravel5.4. Thank you Antonio!

The newest featured added for 5.4 version are:

  • new layout;
  • Laravel 5.4 compatibility;
  • Title config String or Closure;
  • Favicon (png only) config String or Closure;
  • ENUM config Array or Closure;
  • New ckeditor layout;
  • Images config: Test resize (prevent stretch of image) and incremental naming (name*_n* if already exist);
  • Bugfix: wysiwyg loading on settings.

You can find this fork on Github:

How to install Laravel-Admin

From the directory of your project install the package via composer:

composer require "exodusanto/administrator: 5.4.*"

This command will update your composer.json file and install all the needed files under /vendor/ directory.

You need to “publish” some files. With the verb “publish” I mean copying some files delivered in/vendor/ directory to the right place. We have 2 kind of files: configuration file and public assets:

  • config/administrator.php: the file with the main configuration of Laravel-Admin;
  • public/packages/forzennode/administrator/*: css, img and js files.

To publish these files:

php artisan vendor:publish

In config/app.php file add the following line in ‘providers’ array:

'providers' => [
...
Frozennode\Administrator\AdministratorServiceProvider::class,
...
],

How to configure Laravel-Admin

To configure the Laravel-Admin you have:

  • a main configuration file named config/administrator.php (created by the above publishing command);
  • to create a directory config/administrator/settings where you will place the configuration files.

Main configuration file

In the main configuration file (config/administrator.php) you can configure a lot of things like: the middleware used for the authentication, the URL or the domain of your admin panel, the configuration directories (where to place your configuration files), the menu structure (you can organize the menu items in a sort of hierarchical tree), the logic that controls the access to your administration panel, login and logout URLs etc. I suggest to have a look to administrator.php file, as it contains all option with default values and, most important thing, each option is well documented.

Suppose to have a “users” table where you store the user of your application and you want to manage it. To keep this tutorial easy, let’s say you want to manage only the “name” and “email” fields.

In order to do that, you need to change this configuration (in config/administrator.php file) by replacing the value of these attributes:

'middleware' => array('web'),
'title' => 'Title App',
'menu' => array('users'),
'home_page' => 'users',
'login_path' => '/login',
'logout_path' => '/logout',

Let me explain these options:

  • middleware: which middleware the system will be use to authenticate the users that try to access to the administration panel;
  • title: the title of your project (the title in the header);
  • menu: the items of your menu, in this case we will have only one item;
  • home_page: the default page of the administration panel. With “users” you have setup a default view that shows the listing of the users;
  • login_path: the path of the login form (the Laravel-Admin will redirect here the users that can’t access the administration panel);
  • logout_path: in the header you will find a call to action to log out the user from the system.

How to manage a Model

In an application you can have several models: User, Product, News etc…

Usually each Model corresponds to a table in the database. For this example I’m going to suppose that:

  • there is a table in the database named “users” that has 2 fields: name and email;
  • there is an Eloquent Model named User that represents the “users” table.

Create a file named users.php in the config/administrator directory (the name is very important because you need to use the same name in the menu and home_page attributes in the main configuration file). The file is:

Here, you can setup the model (model), the columns in the listing (columns), the filter in the listing page (filters), the fields in the edit and creation forms (edit_fields).

--

--

Roberto Butti
Roberto Butti

Written by Roberto Butti

I’m technophile. Vuejs and Laravel enthusiast! #vuejs #laravel. I love #coding

No responses yet