DEV Community

loading...
Cover image for Make a flexible Laravel admin panel in 2 minutes!

Make a flexible Laravel admin panel in 2 minutes!

rezaamini profile image Reza Amini Updated on ・3 min read

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
  • 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 -m=Article
Enter fullscreen mode Exit fullscreen mode

which -m flag is our model.
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 :)

Discussion

pic
Editor guide
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 Author

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