Category: Laravel Development

Laravel Development

  • Laravel RSS and XML Feed

    In this article, we will discuss about how to create RSS feed in Laravel. But first we will discuss an overview about RSS feed.
    RSS is the type of web feed that allows users and applications to receive regular updates from a website or blog of their choice. RSS stands for Rich Site Summary or it often called Really Simple Syndication. RSS feed is read by an RSS reader or a feed reader, which can be web based, a standalone desktop application or a mobile application.
    An RSS fee is delivered in XML format, allowing maximum compatibility between readers.
    In this article, we are going to use laravelium/feed package for generating RSS feed in Laravel application. So, let’s follow the steps below:

    Step1: Install Laravel Project:

    Open your terminal and run the composer command: “composer create-project –prefer-dist laravel/laravel RssFeed”

    Step2: Install the Packages

    In this step we have to install laravelium/feed package using “composer require laravelium/feed” command.
    After installing the package, we have to add service provider under providers array and aliases array.
    Open “config/app.php” file and add service “Laravelium\Feed\FeedServiceProvider::class,” under providers array like this:
    Next, add services under aliases array like this:
    Publish Configure File:
    Run the command in your terminal for publishing the configure file:
    php artisan vendor:publish –provider=“Laravelium\Feed\FeedServiceProvider”. This process is optional, so, you can skip out this process.

    Step3: Configure SQL Database

    Open your database server and create database like this:
    Next, open .env file and setup database credentials like this:

    Step4: Create Model:

    Next, we have to create model and migration file. So, run the command: php artisan make:model Post –m, here “-m” will create migration file also.
    After running the artisan command, open migration create_posts_table.php file and add line of code like this:
    Next, run the migrate command: php artisan migrate. This command will create tables in your database.

    Step5: Creating Dummy data:

    Now we will create dummy data in your database. Open the database/factories/UserFactory.php file and add the fake table like this:
    Open database/seeds/DatabaseSeeder.php file and add the line like this:
    Next, run database seed command; php artisan db:seed
    After running seed command, 50 records of data feed into post table. You can see database post table like this:

    Step6: Create Controller:

    Now we have to create the controller for rss-feed. Run the command:
    php artisan make:controller PostController
    Next, open the “app/Http/Controller/PostController.php” file and add the following:

    Step7: Define The Routes:

    Open routes/web.php file and define your routes like this:
    Next, open the resources/views/welcome.blade.php file and add an RSS link to the welcome page by adding Feed::link in the section like this:

    Step8: Navigate The Browser:

    Enter the URL: 127.0.0.1:8000/feed and you will get your feed like this:

  • How to make Theme in Laravel?

    In this article, I will show you how to make a theme in Laravel.

    Step1: Installation>

    First install the fresh Laravel project. Run composer command in your terminal:
    “composer create-project –prefer-dist laravel/laravel MyTheme”
    Next, after install the project, run larval-themes command like this: This will install the theme directory in you public directory.
    composer require “facuz/laravel-themes”

    Step2: Theme Configuration

    After installation, open config/app.php file and register the service provider with the application.
    Add service provider at provider array:
    Register the facades in the aliases key of your config/app.php file:
    Run command: publish –provider=“Facuz\Theme\ThemeServiceProvider”. This will publish the configuration.
    This will create a global config file at config/theme.php.
    And also add the theme “APP_THEME=themename” at .env file that we are going to use:

    Step3: Create new Theme

    Run the artisan command for creating theme: php artisan theme:create default
    This command will create theme “default” structure under the public folder like this:

    Step4: Basic Usage of Theme

    In this step, I will show you basic usage of theme, how we can use and create the theme.
    First we will add css and js file in our theme asset directory. You can download bootstrap from https://getbootstrap.com/ site. After downloading the bootstrap file, copy the css and js folder and paste it into public/themes/default/assets directory and as well as add the jquery file under js folder.
    Configuration of assets:
    After adding the file under assets directory, open public/themes/default/config.php file and add assets on the asset method of the config file. The config file is convenient for setting up basic CSS/JS, partial composer, breadcrumb template and also metas.

    Step5: Display view from the controller

    First we need to create a controller, run the artisan command php artisan make:controller HomeController.
    Next, open the controller “app/Http/Controller/HomeController.php” file, add data or define the theme:
    Next, we need to create a view file under resources/views/home/index.blade.php. In this view, I have added basic data for viewing your default structure. You can create your own view according to you.
    Define routes for calling the view from the controller. Open routes/web.php and define routes.
    Browse the URL: 127.0.0.1:8000/theme you will get simple output like this:
    In this output, you can see that there is no header and footer structure define. So you can define your own header and footer in your themes directory and as well as you can add files according to your themes requirements.
    For example: In this example, I have structure our header and footer under public/themes/partials directory:
    public/themes/partials/header.blade.php
    public/themes/partials/footer.blade.php
    Navigate URL: 127.0.0.1:8000/theme in your browser, and you will get output like this:
    So, you can create your own theme by adding different files and customizes your theme according to you.

    Note: you can get more information about this theme package:
    Visit this link: https://packagist.org/packages/facuz/laravel-themes

    Theme Cheatsheet

    Commands:

    Command

    Description

    artisan
    theme:create name

    Generate theme
    structure

    artisan
    theme:destroy name

    Remove a theme

    artisan
    theme:list

    Show a list of
    all themes

    artisan
    theme:duplicate name new

    Duplicate
    theme structure from other theme

    artisan
    theme:widget demo default

    Generate
    widget structure.

    Blade Directives:

    Blade

    Description

    @get(‘value’)

    Magic method
    for get

    @getIfHas(‘value’)

    Like @get but
    show only if exist

    @partial(‘value’,
    [‘var’=> ‘optional’])

    Load the
    partial from current theme.

    @section(‘value’,
    [‘var’=> ‘optional’])

    Like @partial
    but load from sections folder.

    @content()

    Load the
    content of the selected view.

    @styles(‘optional’)

    Render styles
    declared in theme config.

    @scripts(‘optional’)

    Render scripts
    declared in theme config.

    @widget(‘value’,
    [‘var’ => ‘optional’])

    Render widget.

    @protect(‘value’)

    Protect the
    email address against bots or spiders.

    @dd(‘value’)

    Dump and Die

    @d(‘value’)

    Only dump.

    @dv()

    Dump, Die and
    show all defined variables.

  • Laravel Project Testing Using PHPunit

    PHPunit is the unit testing for PHP. This is primarily designed for unit testing, where developers should be able to find mistakes quickly in their newly committed code and assert that no code regression has occurred in other parts of the code base. PHPunit includes a lot of simple and flexible assertions that allow you to easily test your code. Basically, the goal of unit testing is to isolate each part of the program and show that the individual parts are correct.

    Testing In Laravel

    Laravel is built with testing in mind. Basically, Laravel will give you PHPUnit as a testing tool out of the box. By default, the phpunit.xml file is already set up for your application. In Laravel project, under the “tests” directories contains “Feature” and “Unit” directory. Where Feature tests focus on larger portion of your code while Unit tests focus on a very small, isolated portion of your code.

    Before running the test in your project, you should have cleared the cache or session, means that no session or cache data will be persisted while testing. For clearing the cache or configuration, you can use the artisan command “php artisan cache:clear” or “php artisan config:clear”.
    Now, in this article we’ll go through Creating & Running Tests in Laravel.

    1. Install Laravel Project

    Enter the composer command to install Laravel: composer-project –prefer-dist laravel/laravel LaravelTesting.

    2. Creating New Test

    2.1. To create a new test case, use the “make:test” artisan command:

    Create a test in the Feature directory:
    • php artisan make:test NameTest
    Create a test in the Unit directory:
    • php artisan make:test NameTest –unit

    Create a new unit test: php artisan make:test UserModelTest –unit

    After running the command, file will be generated under “tests/Unit/” directory. File will be look like this:

    3. Running Test

    Case1:
    After, test has been generated, go to your terminal and run your tests, execute the “./vendor/bin/phpunit” command from your terminal. This will test your 3 files, one is for “Feature/ExampleTest.php” file and two file for “Unit/ExampleTest.php” and “Unit/UserModelTest.php” files.
    After execute the command, tests will look like this.
    Case2:
    Now suppose, we have created one another new unit test file called NewFileTest:
    Files will be generated under “tests” directory:
    After generated the test file, go to your terminal and run the phpunit command: “./vendor/bin/phpunit”. This will check four files such as “Feature/ExampleTest.php”,“Unit/ExampleTest.php”,“Unit/UserModelTest.php” and “Unit/NewFileTest.php”.
    ./vendor/bin/phpunit
    Case3:
    Now, Let’s change the assertion in “tests/Unit/NewFileTest.php” file like this:
    After changed and save it, go to your terminal and enter the “./vendor/bin/phpunit” command and you’ll get a failure assertion like this:
    There are following PHPUnit test method or assertions and you can use these methods as per your test requirements. To learn about these assertions you can visit this link:
    “https://phpunit.readthedocs.io/en/8.3/assertions.html”
    Some assertions are like this:

    • assertThat()
    • assertTrue()
    • assertFalse()
    • assertDatabaseHas()
    • assertStatus()
    • assertJson()
    • assertNull()
    • assertArrayHasKey()
    • assertEmpty()
    • assertEquals()
    • assertFileEquals()
    • assertFileExists()
    • assertFileReadable()
    • assertSame()
  • Laravel Package

    In this article, I’ll go to through a basic example of how to create a Laravel Package in Laravel with few steps:

    1. Create Project

    Fresh installation of the Laravel using: “composer create-project –prefer-dist lravel/laravel projectname”.

    2. Make Folder For New Package

    After install Laravel project, we will follow steps like:

    • Create a new folder “packages” inside main root folder.
    • Next, inside packages folder we will create another folder which will be our vendor or creator name “digital”.
    • Then inside of vendor folder we’ll create another folder with the name of our package name “calc”.
    • Lastly we need to create a “src” folder which is where the code for our package will live.

    3. Create Composer File For Package

    Next, for our packages we need “composer.json” file because every package should have composer.json file, which will contain dependencies and information about the package itself. So inside your terminal navigate to the folder with your package “calc” name and run the following command: “composer init”

    “composer.json” file look like:

    4. Loading Our Package To Main “composer.json” File

    Next, we need to make our package visible to the Laravel structure, open the main “composer.json” file under the root directory and add the namespaces of our packages in “autoload>psr-4”.

    After adding this, run this command: “composer dump-autoload”.

    5. Creating Service Provider

    Next, create a service provider file under your “Packages/digital/calc/src” directory and don’t forget to use your namespace “Vendor\Package_name”. Basically service provider is the main entry of your package. This is where your package is loaded or booted.

    6. Configure Service Provider

    Next, open “Config/app.php” file and add your service provider inside the “Providers array []”.

    7. Create Routes For Package

    Next, inside of your “src” folder create a new “routes.php” file and write the following code:

    Then go to your Service Provider and add the “routes.php” inside “boot ()” method:

    After this, run command “php artisan serve” and enter the URL http://127.0.0.1:8000/calculator in your browser. This we should end up with the page look like:

    8. Creating Controller For Package

    Inside the packages directory under “src” folder create a new Controller file:

    Under this “CalculatorController.php” file don’t forget to include your package namespace and also include the “App\Http\Controllers\Controller;”

    9. Register The Controller

    After creating the controller we need to register the controller inside our Service Provider class in “register ()” method.

    Next, add routes for this controller inside “routes.php” file:

    10. Creating Views For Package

    To create a view, we need create a “views” folder inside “packages/digital/calc/src” directory then create an “app.blade.php” file inside view folder.

    After creating “add.blade.php”, write following code:

    11. Register The Views

    We need to register the views inside our Service Provider class in “boot ()” method.

    12. Navigate Browser

    After creating controller, views and register into service provider then navigate the browser look like:

    • Addition: http://127.0.0.1:8000/add/14/79
    • Multiply: http://127.0.0.1:8000/multiplication/12/12
  • Make Contact Form in Laravel

    Here are some steps to create contact form:

    Step1

    To make contact form in laravel, first open terminal and install laravel project using composer command:
    composer create-project –prefer-dist laravel/laravel Project

    Step2

    After installation of laravel, go to project directory and create a controller for handling http request:
    php artisan make:controller ControllerName
    For example:

    This command has make SendEmailController under app folder directory: “app/Http/Controller”

    After open “SendEmailController.php file”, we have make index function which is root function of this controller and under this function we have write return statement with view method and under this method we have write view file(“send_email”).

    Step3

    After write a method of view file, create a view file under resources folder and under view folder.

    Under this send_email.blade.php file we have made one form for send an email to controller and under this file we have “csrf_field” function for prevent the application from cross side request forgery attack. In this file also we have create the GUI such as text box for store details of name, create text box for store email and create the text area for store the message.
    Under this file we have write the some block of code for creating gui, and validating condition and write code to show success message under condition if form is successfully submitted.

    Step4

    After writing GUI and validation message in the view file, go to SendEmailController file and create method for validating data against form data.

    Under this controller class we have defined the Mail class and create mail statement, for this we can use laravel mailer class. After that we have write some block of code for validating the template class.

    Step5

    After validating data, we go to route folder and web.php file where we setup the route of both method SendEmailController and send_email.blade.php files.

    Under this file we write route class with get method with two arguments: “/sendemail” and “SendEmailController@index”, so when in browser we have type or paste the url “/sendemail” then it will call index method of SendEmailController index.

    And we will route class with post method for send method with two arguments: “/sendemail/send” and “SendEmailController@send”, so when in browser form is submitted and send request to send method then it will execute send method of send email controller.

    Step6

    Now we have proceeded for send email, so we have go to terminal (command prompt)and first stop laravel server and type command: “php artisan make:mail SendMail”

    This command will make Mailable class with name like SendMail under this mail folder in directory “app/Mail/SendMail.php”. In build function we have make dynamic subject which show the name of user who fill the form. And we have to create “dynamic.blade.php” file under the view folder. Under this dynamic php file the email body has taken.

    After the completion of SendMail file we set the variable under the dynamic.blade.php file we store the user name data and show the message query.

    Step 7

    After completed the all php file, now we have set the configuration body for send email from laravel application. For this we have go to “.env” file and here mail driver option for send email. In this env file first we have to set username and password. The user name and password we get from the https://mailtrap.io/.

    To getting the mail username and password we have create an id and after the id created then we have go to the login option. After the login we can see the user name and password:

    Results

    After the completion of all file we have start your server, using server artisan command: “php artisan serve”.
    After run this command this will give you an address of server.

    Then go to your browser and type address “http://127.0.0.1:8000/sendemail”.

    To check validation:

    Successfully submitting form

    Check sender’s mail: Go to you mailtrap.io and check into your mailbox list.

  • Laravel Homestead

    Laravel Homestead provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. Laravel Homestead is an official, pre-packaged Vagrant box. Vagrant is a tool for building and managing virtual machine environments in a single workflow and provides a simple, elegant way to manage and provision Virtual machine.

    Homestead runs on any Windows, Mac or Linux system and includes:

    • Naginx
    • PHP
    • PostgreSQL
    • Redis
    • Memcached
    • Node
    • MariaDB
    • Mailhog
    • Beanstalkd
    • Git

    And include all other software you need to develop amazing Laravel applications.

    Installation of Homestead:

    1. Download And Install The Software

    Before running the Homestead environment in your machine, first, you must install VirtualBox6.x, VMware, Parallels or Hyper-v. You must download and install any of this software. So in this article, I have installed the VirtualBox6.x. You can download VirtualBox6.x from this link: https://www.virtualbox.org/wiki/Downloads.

    After installation of VirtualBox6.x or any of this software, you must install Vagrant. You can download vagrant from link: https://www.vagrantup.com/downloads.html

    2. Installing Homestead:

    Once VirtualBox6.x and Vagrant have been installed, you should add “laravel/homestead” box to your Vagrant installation using the following command in your terminal:

    i. Run this command: “vagrant box add laravel/homestead”
    Running this command in your terminal, it will take few times to install homestead in your vagrant box which depends on your internet connection speed.

    ii. Run this command: git clone https://github.com/laravel/homestead.git ~/Homestead.
    After installing Homestead in vagrant box, then you should have install Homestead by cloning the repository onto your machine

    iii. Run this command: “cd ~/Homestead”

    And then type the command “bash init.sh”

    This “bash init.sh” command will create the Homestead.yaml configuration file.
    IV. Creating SSH key and run the command. After run this command, simply press the enter button whatever command line asks you.
    ssh-keygen –t rsa –C “your_mail@gmail.com”

    3. Configuring Homestead:

    Next, you should edit the “Homestead.yaml” file included in the repository. In this file, you can configure the path to your public SSH key, as well as the folders you wish to be shared between your main machine and the Homestead virtual machine.

    Let’s edit our “Homestead.yaml” configuration file which we generated. Directory of this file is located at: “C:\Users\USER_NAME\Homested”.

    The folders property of the Homestead.yaml file lists all of the folders you wish to share with your Homestead environment.
    And the sites property of the Homestead.yaml file allows you to easily map a “domain” to a folder on your Homestead environment.

    After configuring the “Homestead.yaml” file, you have to edit the “hosts” file, which is located at directory “C:\Windows\System32\drivers\etc”. And add the address (192.168.10.10 homestead.test) at the end of your host file.

    4. Launching The Vagrant Box:

    Once you have edited the Homestead.yaml, run the “vagrant up” command from your Homestead directory. This will boot the virtual machine and automatically configure your shared folders and Nginx sites.

    After the “vagrant up” command, use the “vagrant ssh” command. This will login to you with your virtual machine.

    5. Creating Laravel Project:

    Let’s create our first Laravel project through homestead. Type the command “composer create-project –prefer-dist laravel/laravel test”. It will create new Laravel project in a folder name test.

    Installation of laravel project

    6. Running Our Application:

    Enter “homestead.test” from your browser and make sure homestead is running. You will see welcome page now.

  • Laravel Cron Job

    In this article, I’ll discuss an overview about Cron and then we’ll discuss, how to add or perform cron (Task scheduling) in Laravel.

    Why we need to use cron job?

    Because if you want to schedule your task like as, you want to send email automatically to users on daily morning or months or you want database log will be clear after week or months, therefore cron job will be needed to perform these scheduled tasks.

    What is Cron?

    Cron is basically a task scheduler, which perform the scheduled tasks at certain intervals. It typically automates system maintenance or administration though its general purpose nature makes it useful for things like downloading files from the interval and downloading email at regular intervals. For managing the schedule process cron uses a configuration file called crontab or cron table.

    How to add Cron Job in Laravel.

    Laravel command scheduler allows you to define your command schedule within Laravel itself. Basically your task schedule is defined in the “app/Console/Kernel.php” method. In this article, I will add a cron in Laravel and define a simple task to perform clear the data entries from the database table. Now, just follow these steps:

    Step1: Install Laravel

    Run the composer command: “composer create-project –prefer-dist laravel/laravel TaskSchedule”.

    Step2: Setup Database Entries:

    Run the artisan command: php artisan make:auth. This command will create authentication in your laravel project.

    Next, create database and link with you Laravel project:
    Create Database:

    Open .env file and add Database entries like this:

    run the migrate command: php artisan migrate. This will create tables in your database.

    After migrate command database table look like this:

    Next, open browser and navigate the browser “localhost:8000/register” add entries for users table in database like this:
    Register User’s in user table:

    Database user’s table look like this:

    Step3: Defining Schedules:

    Create Command
    In this step, we create our custom command. This will execute with task scheduling. So, runs the artisan command: “php artisan make:command everyMinute”

    Next, open the app/Console/Commands/everyMinute.php file and make some change in signature, description, and in handle() function like this:

    Register on Task Scheduler

    In this step, our task schedule is defined in the “app/Console/Kernel.php” file’s schedule method. So, open Kernel.php file and defined the task like this:

    Now, you can check your own custom command created or not. So, run the command “php artisan list”. You will result like this:

    Step4: Run Scheduler:

    Finally, run the scheduler command and test your cron job. “php artisan schedule:run”

    After running the scheduler, your data will be cleared from your database users table.

    #Schedule Frequency Options:

    There are a variety of schedules you may assign to your task:

    Method Description
    ->cron(‘* * * * *’); Run the task on a custom Cron schedule
    ->->everyMinute(); Run the task every minute
    ->->everyFiveMinutes(); Run the task every five minutes
    ->->everyTenMinutes(); Run the task every ten minutes
    ->->everyFifteenMinutes(); Run the task every fifteen minutes
    ->->everyThirtyMinutes(); Run the task every thirty minutes
    ->->hourly(); Run the task every hour
    ->->hourlyAt(); Run the task every hour at 17 mins past the hour
    ->->daily(); Run the task every day at midnight
    ->->dailyAt(’13:00’); Run the task every day at 13:00
    ->->twiceDaily(1, 13); Run the task daily at 1:00 & 13:00
    ->->weekly(); Run the task every week
    ->->weeklyOn(1, ‘8:00’); Run the task every week on Monday at 8:00
    ->->monthly(); Run the task every month
    ->->monthlyOn(4, ’15:00’); Run the task every month on the 4th at 15:00
    ->->quarterly(); Run the task every quarter
    ->->yearly(); Run the task every year
    ->->timezone(‘Asia/Kolkata’); Set the timezone
  • What is Composer

    Composer is an application level package manager for the PHP language that provides a standard format for managing dependencies of PHP software and libraries. In other words we can say that, “it is a tool for dependency management in PHP”, which deals with “packages” and “libraries”.

    Composer runs on “command line” and allows you to declare the libraries your projects depends on and it will manage (install/update) them for you. But it manages them on a per-project basis and installing them in a directory inside your project.

    Note: Composer is strongly inspired by Node.js’s “npm” and Ruby’s “bundler”.

    Composer allows users to install PHP application that are available on “Packagist” which is its main repository containing available packages. Link: https://packagist.org.

    What does composer do?

    Suppose:

    • You have project that depends on a number of libraries.
    • Some of those libraries depend on other libraries.

    Composer:

    • It enables you to declare the libraries you depend on.
    • Finds out which version or packages need to be installed, and it downloads them into your project.

    Basic Commands

    Composer offers several commands parameters including:
    1) require: this command add the library in parameter to the file “composer.json” and install it.
    2) install: this command install all libraries from “composer.json”, and use to download all PHP repository dependencies.
    3) update: update all libraries form “composer.json”.
    4) remove: uninstall a library and remove it from “composer.json”.

    Supported Framework

    • Laravel (version 2 and later)
    • Symfony (version 4 and later)
    • CodeIgniter (version 3.0 and later)
    • CakePHP (version 3.0 and later)
    • FuelPHP (version 2.0 and later)
    • Drupal (version 8 and later)
    • TYPO3 (version 6.2 and later)
    • SilverStripe (version 3.0 and later)
    • Magento (version 2.0 and later)
    • Yii (version 1.1 and later)
    • Zend Framework (version 1 and later)
    • Silex (web framework)
    • Lumen (web framework)

    System Requirements:

    • Composer requires PHP 5.3.2 or latest version to run on your machine.
    • Composer is multi-platform and it run equally well on Linux, Windows, and macOS.
    • A few PHP sensitive php settings and compile flags are also required, but when using installer you will be warned about any incompatibilities.

    How to use it with Laravel?

    Basically, to work in the Laravel framework you have to install the composer first. Without composer Laravel framework does not work. So, before using Laravel, make sure you have composer install on your machine.

    Installing Composer

    Installing Composer is easy. You can get information about installing composer at https://getcomposer.org/.

    After download and run composer-setup.exe. It will install the latest Composer version and set up your PATH so that you can call “composer” from any directory in your command line.

    Fig (a): Options in composer

    In Laravel, composer commands are used for creating the project, as well as used for update the laravel version, clear cache, upgrade and for other work as per requirement.

    Fig (b): Available commands in Composer

    For creating the Laravel project, type the command in your terminal “composer create-project –prefer-dist laravel/laravel projectname”. Without Composer command, Laravel project will not create.

    For example

  • How to create an Admin-Panel in Laravel

    In this, article we will discuss the creating an Admin Panel. As we know admin panel is one of the most important modules for your web or mobile application. In admin panel there is no role of application End users, only an Admin has the role to manage the application.

    In this article, we have customized the admin panel and add some features such as: add new users, delete update users, login and signup page. If an Admin Login to an Admin Panel and do some activities like CRUD (create, read, update and delete) operations then activity should be created and should be available for Superuser to see.

    How to create an Admin-Panel in Laravel?

    1. Create Laravel Project

    First you have to create a Laravel project using composer command:
    “Composer create-project –prefer-dist laravel/laravel project_name”

    2. Choose Performance Over Personalization

    In this user have two options for designing user interface or download the free available theme for an admin panel. So many of designers download the theme and customize the theme as per user’s requirements. Downloading template will help to save time for creating the user interface.
    So, in this article, I have downloaded the template and use their css, and java scripts file and customize the pages.

    Steps for applying template in Laravel
    2.1. First you have to download the template and after that copy the folder like css, js, scss, and image or assests folder. And go to your Laravel project directory and paste these assests folder in public directory of your laravel project.

    2.2. Next, after copying the assets under the public directory, then we will create a master file under the “resources/view/layouts” directory. In this “master.blade.php” we have added and edit the template file code which has a user interface for the admin-panel. Then we will create a “dashboard.blade.php” file under the “resources/views/admin” folder, you can manually create the layouts and admin folder under these resources. This “dashboard.blade.php” file is used we have used for routing the dashboard of Admin panel.

    master.blade.php file

    dashboard.blade.php file

    3. Database Connectivity

    3.1. In this article, I have used the Wamp server for database. Go to the phpMyAdmin option in Wamp and create database look like:

    3.2. Next, open “.env” and edit database connection look like:

    4. Create Login Interface Using Authentication:

    Laravel provide the authentication command for creating the login interface. Here we discussed how to setup an authentication for your project.
    4.1. First run the artisan command in your terminal under your laravel project:
    “php artisan make:auth”.

    This command will create the authentication folder under “views/auth” directory.

    4.2. After auth command, go to “database/migration/” and open file “create_user_table.php”. Under this file we have add two field “phone” and “usertype” field for admin panel.

    4.3. After that, open file “register.blade.php” under the “resources/views/auth” and write code for adding the phone label field.

    4.4. Next, we will modify the “User.php” file (“app/user.php”) and “RegiserController.php” file located at “app/http/Controller/auth/RegisterController.php”.

    User.php

    RegisterController.php

    4.5. After modifying the files, run the migrate command:
    “php artisan migrate”

    After running this command, tables are created automatically in your database look like:

    4.6. After migration, navigate the URL: http://127.0.0.1:8000 into your browser, and register the user.

    Register User

    Manually define usertype “admin” into your database
    Then go to for middleware to redirect this admin into your dashboard.

    5. Creating Middleware:

    After completing the setup of dashboard, database and authentication setup add middleware for redirect to the admin dashboard.
    5.1. Run the middleware command: “php artisan make:middleware middleware_name”

    Next, go to directory “app/http/middleware/” and open “AdminMiddleware” file and write code look like:

    5.2. Next, updated the “kernel.php” file under the “app/http/” directory:

    5.3. Next, open the “LoginController.php” file under the “app/http/controller/auth” directory and add class and function like:

    5.4. After the completion of middleware, route the dashboard using middleware in the Laravel. Open “web.php” file under the “routes” directory.

    6. Login In Admin Panel

    6.1. Open browser navigate the URL: http://127.0.0.1:8000/dashboard.

    6.2. After navigating the URL, The login page will redirect after that enter the admin credentials:

    6.3 After entering admin credentials, Dashboard page will open:

    6.4. Logout

    6.5. Register User’s

    6.6. User’s Profile

    6.7. Edit User’s by Admin

    6.8. Delete User

    Note: you can download the code form GitHub directory, link: https://github.com/digitalcrm/Admin-Dashboard.

  • Admin Panel in Laravel

    In this article we will discuss the how to create admin panel in Laravel. So, creating an admin panel in Laravel we have use the Laravel package “Voyager- The Missing Laravel Admin”.

    So, the first question arises is why we using the “Laravel Voyager” package. Basically “Voyager” is a powerful package to handle the complex operations such as handling the CRUD (create, read, update and delete) operations and also the optimization of the server side and client side code.

    Voyager has the BREAD system, which allows you to browse, read, edit, add and delete any content on your site. Voyager is simply an admin for your application, you have full control over how your Laravel application will function on the front-end and then you can pass off the entire administrative task to Voyager.

    Features provided by Voyager package:

    • Module Management
    • Roles and Permissions Management
    • Routing
    • Media Manager
    • Menu Builder
    • BREAD Builder
    • Compass
    • The Database Manager
    • Multi Language Support

    Note: To know more about “Voyager” visits this link: https://voyager.devdojo.com/.

    Installation or Creating Admin Panel

    1.First you have to create a “Laravel” project inside your project directory. Run this command using the composer: “composer create-project –prefer-dist laravel/laravel projectname”.

    2. Once the project installs, you can include the “Voyager package” with command: “composer require tcg/voyager”. Run this command in your terminal inside your Laravel project directory.

    3. After running the voyager command, create a new database.

    4. After creating a new database, then go to your project and modify database driver in the “.env” file and also modify the “APP_URL”.

    5. Next, open your project, go to directory “config/app.php” file and add the Voyager Service provider in the provider array.
    “TCG\Voyager\VoyagerServiceProvider::class,”
    “Intervention\Image\ImageServiceProviderLaravel5::class,”

    6. Finally, you can install Voyager. There are two options to create admin panel with a dummy data or without dummy data. Commands are:
    With dummy data: “php artisan voyager:install –with-dummy”.
    The dummy data will include 1admin account (if no users exist), 1 demo page, 4 demo posts, 2 categories and 7 settings. This will contain the default login credentials:
    Email: admin@admin.com
    Password: password
    OR
    Without dummy data: “php artisan voyager:install”.
    In this article, I have installed the Voyager using dummy data.

    7. After successful installation navigate to “http://localhost/admin/”.

    After browse the address, you will be asked to enter the user name and password.

    After Login, the dashboard homepage will look like this:

    User’s panel

    Add New user in Users panel

    adding users, it will look like

    Note: In this panel, you can customize the dashboard as you wish to want and you can add more features. The directory of this panel is located at: “vendor/tcg/voyager”.