DEV Community

Cover image for Make a flexible Laravel admin panel in 2 minutes!
Reza Amini
Reza Amini

Posted on • Updated on

Make a flexible Laravel admin panel in 2 minutes!

Have you ever tried to build a complete admin panel in Laravel from zero?

It takes lots of energy and time and, you may not like what you have built.

I had the same problem as you, When I was trying to make an admin panel and I think to myself and I said: Reza there are lots of people who want to build a beautiful admin panel like you, make your module more flexible and share It in Github.

Wow, It's very good I should do it for the open-source community.

So I decided to build an admin panel module and because I love Livewire I decided to do that with Livewire.

If You don't know what is Livewire I should tell You It is a Fullstack framework and makes You needless from Javascript frameworks.

Come on dude, don't say too much show us your package...

Ok, let me tell you about EasyPanel.
EasyPanel is an admin panel package for Laravel and You can build your admin panel in 2 minutes (maybe less than 2 minutes).

There are some features of EasyPanel :

  • Create CRUD in the config file.
  • Manage route prefix and addresses
  • Beautiful UI/UX with AdminMart template
  • Add/remove Admins with command line
  • Every UserProviders and Authentication classes are customizable and you can change them
  • You can create your own routes and customize our views and components
  • Manage pagination count
  • Multi lang
  • Real-time validation with Livewire
  • Customize every action in your project
  • A small and beautiful TODO (You can disable it in your config)
  • Create a nice and responsive view based on your data in the config file for every CRUDs
  • Custom validation based on the config file
  • Ajax search with Livewire in every column you want

So We saw the features, But let's build an admin with articles section (Create, Read, Update, Delete)

first of all, We must install the package (how 🤔)
Don't be afraid It's very easy as the package name.

Install the package with Composer.

composer require rezaamini-ir/laravel-easypanel
Enter fullscreen mode Exit fullscreen mode

next, We should publish configurations and styles (Just with one command) :

php artisan panel:install
Enter fullscreen mode Exit fullscreen mode

Congratulations 👏! You have installed the package.

Now We have access to the config file in config directory and we can pass our cruds to actions key in the easy_panel.php file.

To create a CRUD we must pass 3 steps:

1- Create a CRUD config file.

To create a CRUD config we must run this command out:

php artisan panel:config Article
Enter fullscreen mode Exit fullscreen mode

which Article is our model name.
the file will be created in resources/cruds/article.php

2- Config our CRUD file and pass the data that we want.

let's write our array in the CRUD file :

return [
    'model' => \App\Models\Article::class,

    // searchable field, if you dont want search feature, remove it
    'search' => ['title', ['user' => 'name']],

    // Manage actions in crud
    'create' => true,
    'update' => true,
    'delete' => true,

    // Validation in update and create actions
    'validation' => [
        'title' => 'required',
        'content' => 'required|min:30',
    ],

    // Write every fields in your db which you want to show
    'fields' => [
        'title' => 'text',
        'content' => 'textarea',
        'image' => 'file'
    ],

    'store' => [
        'image' => 'image/articles'
    ],

    //Default that data you want to pass in create and update actions, Do not you want? Delete this key.
    'extra_values' => [
        'user_id' => 'auth()->user()->id'
    ],

    // which kind of data should be showed in list page
    'show' => ['title', 'image',  ['user' => 'name']],
];

Enter fullscreen mode Exit fullscreen mode

Now we must pass 'article' value in our config file in config/easy_panel.php in actions key like:

'actions' => ['article', 'user']
Enter fullscreen mode Exit fullscreen mode

3- Run CRUD creator command:
with one command We can create our CRUD action with routes and everything which a panel needs...

php artisan panel:crud article

Now we have an admin panel with an Article section and a default TODO list.
So easy 😁.

Let's see what we build :
Admin panel

This is a simple example of this package and you can customize every file in your project.

Repository address :
https://github.com/rezaamini-ir/laravel-easypanel

Don't forget to star to the package ⭐.

You are free to submit a pull request :)

Top comments (19)

Collapse
 
achala87 profile image
Achala Arunalu Meddegama • Edited

Hi. thanks for the lovely admin panel. I'm new to laravel and setup your admin panel on one of my volunteer projects at buildlk.com

there was a question about how to edit the list views but found the solution. The partial blade views were a little mystery :) Thanks the admin dashboard is awesome.

Collapse
 
rezaamini profile image
Reza Amini

When you try to update the crud config file you have to rerun php artisan panel:crud -f with -f flag to recreate the files.

Collapse
 
bsuchea profile image
BEY Suchea

How about role and permission ?

Collapse
 
rezaamini profile image
Reza Amini

We will implement role and permission in new versions!

Collapse
 
pk8892411327 profile image
PK8892411327

127.0.0.1:8000/admin 404 not found error

Collapse
 
codepiter profile image
Pedro Sanchez

ups i stayed at step 1:
$ php artisan panel:config article -m Article

The "-m" option does not exist.

Collapse
 
rezaamini profile image
Reza Amini

Thanks!
It was edited, in the new version, you don't need to pass -m flag and you have to pass your model name directly.

Collapse
 
tayfnour profile image
M.Hassane • Edited

How to overwrite crud?

Collapse
 
rezaamini profile image
Reza Amini

What do you mean by "overwriting CRUD"?

Collapse
 
deivi7 profile image
David

How to use a select field from the configuration file?

Collapse
 
rezaamini profile image
Reza Amini

Hey,
You have to use this syntax :

'ground_name'=> [
    'select' => ['indoor', 'out']
]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
radumro profile image
Radu Martin

I think that you forgot to create the model and migration for articles ...

Collapse
 
rezaamini profile image
Reza Amini

Article in this project is just an example
We are not going to create an article section

Collapse
 
indriti1 profile image
Indriti1

What is the route for accessing the panel?

Collapse
 
rezaamini profile image
Reza Amini

The default route is '/admin' but you can change it in the config file

Collapse
 
jonatemps profile image
jonathan Mupene • Edited

Why?

PS C:\laragon\www\easyPanel> php artisan panel:config article -m=Article
'article' must be equal to model name

Collapse
 
rezaamini profile image
Reza Amini • Edited

php artisan panel:config Article
Use this format.

Collapse
 
nibirahmed9611 profile image
Nibir Ahmed

Hey,
Thanks for the admin panel. But the thing is how can I authenticate? I've installed laravel ui. Should it work?

Collapse
 
rezaamini profile image
Reza Amini • Edited

You have to authenticate user in your project without this panel's feature!
It will check if the is_superuser or anything which has been set in config for logged in user is true then it lets users access to panel.