Friday, December 2, 2016

Upgrade PHP version to PHP7 quickly on LAMP environment

Run Following commands:

$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install -y php7.0
After that run following command:

sudo apt install php libapache2-mod-php
Now restart  Apache server :


sudo service apache2 stop
sudo service apache2 start
Repository required to install phpmyadmin

sudo add-apt-repository ppa:ondrej/php5-compat

Thursday, November 3, 2016

Laravel 5.3 default authentication

In this tutorial i'll give  basic idea of authentication system provided by laravel 5.3. You can find more details about authentication system in this video tutorial.

Authentication system is one of the core module of an web application. It will take a lot of time to develop an authentication system without security flaws.

Laravel 5.3 provides quick and easy to scaffold all of the routes and views you need for authentication.

Use following command  and laravel will setup everything for you.

php artisan make:auth
and make sure you ran following command which will required for registering new users and reset password.

php artisan migrate
Now we have everything running. If we browse our web application we'll see two link. One is Register and another one is Login .


Now if you want to create new user , click Register and you'll see following page:

Provide Necessary details and you will be redirect to user dashboard.


Laravel also generate default login page for you.


you can find all the routes related to laravel authentication system in auth() function on following directory:
vendor/laravel/framework/src/illuminate/Routing/Router.php 

Sunday, October 23, 2016

Api authorization with Passport in Laravel 5.3

This tutorial is basically an environment set up to understand how Passport works in Laravel 5.3.

Passport is a way to manage authentication for accessing API in Laravel. It is very easy to implement and user do not need to concern about background activities   of Oauth.

To implement Passport in local environment , we need two projects. One will be working as server, which authenticate a user and another one will be working as client, which will request for resource via API.


so i am using two laravel 5.3 instances as server and client.

Server is running on localhost:8000
Client is running on localhost:9000

Here is the instructions that must be followed to setup oAuth server on our Server(localhost:8000)

1. composer require laravel/passport

Register PassportServiceProvider in providers array on app.php file

2. Laravel\Passport\PassportServiceProvider::class,

Migrate tables related to Passport.

3. php artisan migrate

Create Encryption key to generate secure access key

4. php artisan passport:install

Add HasApiTokens traits is used in User model, which will provide some helper functions to play with access tokens.

5. <?php

namespace App;

use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;
}

Now in AuthSericeProvider's boot function add following codes to automatically set up required routes related to passport

6.  public function boot()
    {
        $this->registerPolicies();

        Passport::routes();
    }

Now in config/auth.php file set Passport as API driver


7. 'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],

Now run following code to publish vue components related to Passport.


8. php artisan vendor:publish --tag=passport-components
Now add following code in app.js file


9. Vue.component(
    'passport-clients',
    require('./components/passport/Clients.vue')
);

Vue.component(
    'passport-authorized-clients',
    require('./components/passport/AuthorizedClients.vue')
);

Vue.component(
    'passport-personal-access-tokens',
    require('./components/passport/PersonalAccessTokens.vue')
);

Now we have to compile this by running following code

10.
   gulp watch



Now add following lines in the view page in order to give access to admin to create client, personal access token.


11.
<passport-clients></passport-clients>
<passport-authorized-clients></passport-authorized-clients>
<passport-personal-access-tokens></passport-personal-access-tokens>
Now our server configuration done. Now we'll create new client in order to give access.

12.


Now we'll setup our client

In Client's web.php file add following code :

1.
 use Illuminate\Http\Request;

Route::get('/', function () {
    $query = http_build_query([
        'client_id' => 12,        'redirect_uri' => 'http://localhost:9000/callback',        'response_type' => 'code',        'scope' => '',    ]);
    return redirect('http://localhost:8000/oauth/authorize?'.$query);});
Route::get('/callback', function (Request $request) {

    $http = new GuzzleHttp\Client;
    $response = $http->post('http://localhost:8000/oauth/token', [
        'form_params' => [
            'grant_type' => 'authorization_code',            'client_id' => 12,            'client_secret' => 'rfkixBY5v3SwnqwRM570yKHfgQMRNyNDd1WgOxWP',            'redirect_uri' => 'http://localhost:9000/callback',            'code' => $request->code,        ],    ]);
    return json_decode((string) $response->getBody(),true);    

});

So our basic setup done. Now if we'll try to access localhost:9000 we'll be redirect to following page:

2.


Now if we authorize we'll see access token as follow

3.

Now our system is working fine. If we go to localhost:8000 and refresh our browser , we'll see following view

4.


We can also create personal access token. To generate personal access token we need to create a Password grant client using following command:

1 . php artisan passport:client --password 

Now in our server application we can create personal access token.



Thursday, September 29, 2016

Python Connect Database Using peewee


First install peewee using pip

pip3 install peewee
Now we have to install MySQLdb or PyMySQL

To install PyMySQL run following command:
sudo pip3 install PyMySQL
Now our basic Configuration done.
Lets create a sample program to connect database and retrieve information from an existing table
import peewee
from peewee import *
db = MySQLDatabase('Word', user='root' , passwd='csecu')


class Words(peewee.Model):
    name = peewee.CharField()
    engdes = peewee.CharField()
    pages = peewee.IntegerField()

    class Meta:
        database = db


for words in Words.filter(name="bappu"):
    print(words.pages)
Lets breakdown :

db = MySQLDatabase('Word', user='root' , passwd='csecu')
This line is used to establish a database connection.

class Words(peewee.Model):
    name = peewee.CharField()
    engdes = peewee.CharField()
    pages = peewee.IntegerField()
Here class Words, represents that, we have a table name words in Word database and it has 3 columns. Which are name, engdes and pages 

class Meta:
        database = db

This means that Words model uses the "Word" database.
for words in Words.filter(name="bappu"):
    print(words.pages)
This is used to select all data where name = bappu and showing number of pages

Thursday, September 1, 2016

Up & Running With Gulp

Check Older version if installed

$ npm rm --global gulp
  Install Gulp Globally
$ npm install --global gulp-cli
Initializing Project directory
npm init
Installing Dependencies
npm install --save-dev gulp
Creatng gulpfile.js in root directory
var gulp = require('gulp');

gulp.task('default', function() {
  // place code for your default task here
});
Preprocessing with Gulp 

Compile Sass to CSS with the help of gulp-sass PKG

$ npm install gulp-sass --save-dev

 --save-dev flag to ensure that gulp-sass gets added to devDependencies in package.json Now add following line to gulpfile.js
var sass = require('gulp-sass');
  Now add following line in gulpfile.js
gulp.task('sass', function(){
    return gulp.src('css/sass/shuvrow.scss')
        .pipe(sass()) // Using gulp-sass
        .pipe(gulp.dest('css'))
});
Now add watch to change dynamically.
 Add following line on gulofile.js
gulp.task('watch', function(){
    gulp.watch('css/sass/shuvrow.scss', ['sass']);
    // Other watchers
})
Now run following command in terminal
gulp watch
Now you can see shuvrow.css file changes automatically.
Live Reloading => Auto sync 
Run Following command:

npm install browser-sync --save-dev
Add following line on gulpfile.js
var browserSync = require('browser-sync').create();
Now add following lines
gulp.task('browserSync', function() {
  browserSync.init({
    server: {
      baseDir: ''
    },
  })
})
Now update following code
gulp.task('sass', function(){
    return gulp.src('css/sass/main.scss')
        .pipe(sass()) // Using gulp-sass
        .pipe(gulp.dest('css'))
});
to
gulp.task('sass', function(){
    return gulp.src('css/sass/main.scss')
        .pipe(sass()) // Using gulp-sass
        .pipe(gulp.dest('css'))
        .pipe(browserSync.reload({
            stream: true
        }))
});
Now, we have to run both the watch and browserSync tasks at the same time for live-reloading
To do this update following codes
gulp.task('watch',function(){
    gulp.watch('css/sass/main.scss', ['sass']);
    // Other watchers
});
to
gulp.task('watch',['browserSync','sass'], function(){
    gulp.watch('css/sass/main.scss', ['sass']);
    // Other watchers
});
Now run gulp watch command on terminal to see all new changes on browser automatically.

Tuesday, August 23, 2016

Install laravel 5.3 in Ubuntu 14.04


Once again Laravel comes with many amazing features and i can't wait more to try this all out.

In this post i am going to write how to setup laravel 5.3 in Ubuntu 14.04.
I am planning on making video for each of this post. Here you can find more about installation of l5.3 on ubuntu
In laravel documentation, it says
  • PHP >= 5.6.4
required to install laravel 5.3.

So first run following command on terminal:

  • php -v
This will show you, your current php version.


As you can see, i have PHP version 5.5.9 , so i have to upgrade it to  >=v5.6.4

So to do this i have to run following commands:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php5-5.6
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install php5
Now if i check my updated php version i can see this :


So my php version updated as i needed.

Now i have to run following command to install new Laravel 5.3 setup

composer create-project --prefer-dist laravel/laravel HighFive
So my installation is done.

Now i have to go to project directory and run following command
php artisan serve
Now if i go to browser and browse localhost:8000 , hurry laravel 5.3 is on..


Laravel Elixir Setup and Uses



Laravel Elixir provides a clean, fluent API for defining basic Gulp tasks for your Laravel application. Elixir supports several common CSS and JavaScript pre-processors, and even testing tools. Using method chaining, Elixir allows you to fluently define your asset pipeline. For example:
elixir(function(mix) {
    mix.sass('app.scss')
       .coffee('app.coffee');
});
Gulp is a task/build runner for development. It allows you to do a lot of stuff within your development workflow. You can compile sass files, uglify and compress js files and much more.

Installation & Setting Up

  • First Setup Node
    • Try Following command to check node version
      • node -v 
          
  • Install Gulp Globally
    • Try Following command 
      • npm install --global gulp-cli (for windows)
      • sudo npm install --global gulp-cli (for linux)
      • npm install -- (to install npm dependency: use sudo for linux do install all dependency)
After   Installing all dependency , run following code to notify all changes related to app.scss or any file your are willing to work.







  • gulp watch 
  • Lets say, we want to make change to app.scss and convert it to css file under public folder.
    To do this, first change 
    elixir(function(mix) {
        mix.sass('app.scss')
           .coffee('app.coffee');
    });
    to

    elixir(function(mix) {
        mix.sass('app.scss','public/style.css');
    });
    now change code in app.scss file and you'll see all changes in public/style.css file.

    Sunday, August 14, 2016

    Integrate Redis on Laravel 5.2

    In this tutorial i am going to write basic steps to integrate Redis with laravel 5.2 

    Steps

    First

    Install Redis server on your system.

    I am using  Ubuntu 14.04. Following commands will setup Redis Server on your machine.



    sudo add-apt-repository ppa:chris-lea/redis-server
    
    sudo apt-get update
    
    sudo apt-get install redis-server
    
    Now start Redis server using following command
    sudo service redis-server start
    
    If everything is okay, you'll see this message on Terminal
    Starting redis-server: redis-server
    
    For windows user, you can find details about installation in here After successfully installing Redis server on your system, now we have to integrate it with Laravel 5.2 project.
    To do that, we need to install predis/predis package  via composer.
    Go to your project directory and from terminal run this command
    composer require predis/predis
    After installing predis/predis package via composer, we have to configure it.
    Now open .env file in a text editor and add following line at the buttom.

    #CACHE_DRIVER=redis
    #SESSION_DRIVER=redis
    CACHE_DRIVER=file
    SESSION_DRIVER=file
    QUEUE_DRIVER=sync
    
    REDIS_HOST=127.0.0.1
    REDIS_PASSWORD=null
    REDIS_PORT=6379
    You can change it depending on your system's environment.
    Now our integration is done and it's time to test it.

    To test it, go to routes.php file and add following line
    use Illuminate\Support\Facades\Redis;
    Now add following line
    Route::get('redis/test',function(){
        $redis = Redis::connection();    
    $views=$redis->incr('view');
        dd($views);});
    Now run following command on terminal:
    sudo service redis-server start
    
    php artisan serve
    After starting project, open your browser and browse
    localhost:8000/redis/test
    Now you'll notice , every time you browse this url, value showing on browser always incremented by one.

    Saturday, August 13, 2016

    Opencart 2.3 landing page Bisection

    I am new to opencart 2.3 and i am learning through debugging how this e-commerce platform working.

    In this post , i am writing about changing landing page which is changing route common/home to something new. i.e uncommon/home

    I have been trying to find the root from where opencart 2.3 is routing to common/home.  After few hours (i am slow at learning but persistent )i found that the default route is found from system/config/default.php file.

    If you look carefully , you can see
    $_['action_default']        = 'common/home';
    this line.
    So if we change  the value of
    $_['action_default']
    then we can route to different landing page.

    Now, my intention was to setting up different landing page and the test route was decided as  uncommon/home.

    To make it work, first i copied all the files from catalog/controller/common directory to a new directory called catalog/controller/uncommon.

    Now change all the class name under catalog/controller/uncommon directory as follow:
    • Cart.php file
          ControllerCommonCart to ControllerUncommonCart 
    • column_left.php file
        ControllerCommonColumnLeft to ControllerUncommonColumnLeft
    Now replace all occurrence of common common with uncommon.

    Do exactly same for all other files under uncommon directory.


    Now lets create view files for all these controller to show data.

    Go to catalog/view/theme/default/template directory.

    Copy all files from catalog/view/theme/default/template/common  to catalog/view/theme/default/template/uncommon directory.

    So our basic setup completed. Now we'll change default route to our new created route.

    To do so, we have to change value of 
    $_['action_default'] as  'uncommon/home'

    Finally Login as admin in your projec and go to layouts section.
    Select home and click edit button.
    Now change the route
    'common/home' to 'uncommon/home'
    Now we are done our all set up.
    If we browse our project's landing directory, we'll see our newly created pages which are showing by routing
    'uncommon/home'
    Now change the files under uncommon directory as you like and reload browser to see the updates.

    Setting up header to collect data from API

    Get data from api Set header :
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
    header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With');
    header('Access-Control-Allow-Credentials: true');
    
    now get Get data using method : get or post from front end.

    Basic Git command and remotely update to Github

    In this tutorial i’ll write basic git command to create local git repository , staging changes, committing and push changes to remote git repository.


    First, We have to know what is git?
    Git is a open source distributed version control system.It is free and designed to handle everything from small to very large projects with speed and efficiency.
    
    Now one question may arise on our mind. What is version control system?
    well, Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.
    
    Now we know what is git and why we must use it.
    Our next step would be setting up git in our local machine.

    Setup Git

    *Linux
    sudo apt-get install git
    
    *Windows
    Simply download the installer exe file from the GitHub page, and run it. Git installer
    Lets start working with git!
    1. Empty Git Repository Setting Up
      To initialize a empty git repository in local machine first you have to go the directory where you want to create repository. Then write this command in terminal.

      git init

      enter image description here
    2. Check current Status of repository
      After initializing empty repository lets check current condition of repository.To do so, type this command in command line

      git status
    enter image description here

    3. Adding changed file to commit
    In our last step we created a file called helloGit.html and checked status whether it shows update or not. Now we will add this html file to stage state so that we can track further change happen to it.
    How can we do that? Write this command on terminal
    git add helloGit.html
    
    Now check current status using previous command
    enter image description here


    4. Now Committing new this change with a hints
    Now we have to keep information about this change so that we differentiate it with previous changes. To do that, write this command in terminal.
    git commit -m "Creating helloGit.html page"
    
    enter image description here
    Now lets check current git repository status using git status
    and we will see this
    enter image description here

    5. Now we’ll push it to github.com
    In this step we’ll push our updates to github.com.
    To do that we have to create a repository in github.com.
    Go to github.com and create a new repository name basicGitCommands
    Now to connect basicGitCommand repository from our local machine , we have to set it as origin.To do that, we have to write this command.
    git remote add origin https://github.com/shuvrow/basicGitCommand.git
    
    Here shuvrow is my user name. Replace it with your user name.
    After writing this command we will see this in terminal.
    If you want to create repository from your local machine using command line, write this command in terminal
    curl -u 'shuvrow' https://api.github.com/user/repos -d '{"name":"basicGitCommand"}'
    
    Now we have external git repository in github.com. So all we’ll going to push it in github.com
    To do this, we have to write this command in terminal.
    git push origin master
    
    enter image description here
    Yes!!! we have done it!
    Here is the view of github.com/shuvrow/basicGitCommand.git
    enter image description here

    Laravel Project Setup Using Composer

    In this tutorial i’ll write the key points that are necessary to create a laravel project/setting a laravel project with the help of composer.

    Composer Setup

    First We have to understand what is composer?
    Well, Composer is a tool used in PHP for dependency management. It allows us to declare the dependent libraries our project needs and it will install them in our project for us.
    Basically we tell composer about the files our project requires and composer will find these files for us.
    Composer does this in two ways.Which are :
    1.Finding the appropriate version of the file
    2.Install them for us
    Now, we need to set up composer in order to create a new Laravel project.
    We can set up composer in two ways in our local machine: Locally or globally.

    Locally setting up composer for *nix system

    1. Run the following command in terminal
    curl -sS https://getcomposer.org/installer | php
    if it fails we can download the installer with php instead,
    php -r "readfile('https://getcomposer.org/installer');" | php
    we can install composer in a specific directory using –install-dir option and providing a target directory
    curl -sS https://getcomposer.org/installer | php -- --install-dir=bin
    Globally setting up Composer
    2. Run the following code In terminal
    curl -sS https://getcomposer.org/installer | php
    Now move the composer.phar file to /usr/local/bin/composer directory using the following command
    mv composer.phar /usr/local/bin/composer
    Now you can run composer from your terminal without using
    php composer.phar
    just run composer
    That’s it!
    Window’s Installation
    In windows you have to download composer and install it like other software.
    Download composer from this link Composer
    Now Install it. After installing Composer find composer.phar file and copy it to your laravel project. You can download Laravel framework here.
    Laravel Framework

    Laravel Set Up in Windows

    Now unzip the downloaded file.Copy composer.phar file here.
    Then run this command in command line
    php composer.phar install

    Laravel Set Up in Linux


    Now you have composer set up in your machine.
    Now we will create a new laravel project using composer.
    Write the following command in your terminal and see the magic of composer!!!
    composer create-project laravel/laravel your-project-name --prefer-dist
    Now you’ll see that composer will download and set up all the necessary files required for laravel project.
    Instead of using your-project-name , use your other name as project name.
    .

    Running laravel

    Now you have a laravel project created by composer. To start building application , first you have to give read write permission to /app/storage directory in your project (Linux).
    In linux environment, you can do that using chmod command.
    Now go to the project directory from command line. You can do that by using cd command.
    Then run this command:
    php artisan serve
    You can see that you got a local server running on port 8000.
    After that go to the web browser and write localhost:8000
    Note
    8000 is the port number where my local server is running. You can change the port number if you like. Use this command to change the port number
    php artisan serve --port=8080
    You can use other number as port number.
    Now you will see a welcome message notifying you that laravel framework is working fine in your machine.

    Install LAMP and PHPmyAdmin && PHPpgAdmin on Ubuntu 14.04

    Install LAMP

    Steps are:
    1. sudo apt-get update
    2. sudo apt-get install apache2
    3. sudo apt-get install mysql-server php5-mysql
    4. sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
    5. sudo gedit /etc/apache2/conf-available/serve-cgi-bin.conf Add this line at the end of the file:
        1. ServerName localhost
       
    6. save this file
    7. sudo service apache2 restart
     

    Install PHPmyAdmin

    Steps are :
    1. sudo apt-get install phpmyadmin
    2. sudo php5enmod mcrypt
    3. sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
    4. sudo service apache2 restart
     

    Install PHPpgAdmin

    Steps are :
    1. sudo apt-get install phppgadmin
    2. sudo gedit /etc/apache2/conf.d/phppgadmin
      • uncomment this line allow from all
    3. sudo ln -s /usr/share/phppgadmin /var/www/phppgadmin
    4. sudo cp /etc/apache2/conf.d/phppgadmin /etc/apache2/conf-enabled/phppgadmin.conf
    5. sudo gedit /etc/phppgadmin/config.inc.php
      • set $conf['extra_login_security'] = true; to false
    6. sudo service apache2 restart

    Laravel 5.2 Implicit model binding

    In Laravel 5.2 new feature called implicit model binding added. Which can be implement efficiently and in a very easy manner. Here how its done :
    1. In your routes.php file create a new route
      Route::get('user',function(){});
    2. Now if you want to retrieve information of a particular user, modify your user route as follow
      Route::get('user/{user}',function(App\User $user){ return $user; 
      });
    Now if you browse your defined route , localhost:8000/user/1
    (Assuming your laravel application running on localhost, port 8000 and you have data on your user table)
    This will return information in JSON format of the user who has id 1.
    Here , App\User is the namespace for User model.

    Laravel 5.2 using queue to send email

    To sent email after desired number of second, first change the .env file as follow.
    • First provide database credential
    • set
      QUEUE_DRIVER=sync to
      QUEUE_DRIVER=database
    Normally , QUEUE_DRIVER=sync tries to sent email immediately and if we set it as database, we can sent email after desired number of seconds. then,
    • give the email credential , from which you want to sent email
    Here i will be using smtp server , so to sent email we have to change gmail setting and give permission to access email account from less secured apps. Here is the link to set access from less secure apps click turn on and you are ready to go. Now go tho the queue.php file in config folder and find the array key database. Here is the information we get:
    'database' => [
        'driver' => 'database',
        'table'  => 'jobs',
        'queue'  => 'default',
        'expire' => 60,
    ],
    
    From this data, we can see that to use database as queue driver we have to create a table called jobs. To create this table, we have to run following command
    php artisan queue:table
    This command will create a migration file which will create a table called jobs with necessary fields. Now we will create a table to track failed jobs. To create this table we have to run following command:
    php artisan queue:failed-table
    
    This command will create a migration file , which will create a new table called failed_jobs Now run following command to create table using this migration files.
    php artisan migrate
    Now, in your .env file set following information
    MAIL_DRIVER=smtp
    #MAIL_HOST=mailtrap.io
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    MAIL_USERNAME=*********
    MAIL_PASSWORD=*********
    MAIL_ENCRYPTION=tls
    MAIL_FROM=*********
    MAIL_NAME=Dushor Alo
    Now go to mail.php file on config folder. Comment out this line
    'from' => ['address' => null, 'name' => null],
    
    and use this code
    'from' => ['address' => env('MAIL_FROM'), 'name' => env('MAIL_NAME')],
    And other settings are
        'username' => env('MAIL_USERNAME'),
        'password' => env('MAIL_PASSWORD'),
        'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    
    Now go to routes.php file and add following lines
    Route::get('send/mail',function(){
        $user=['name'=>'Rashed','email'=>'xyz@gmail.com'];
    
        \Illuminate\Support\Facades\Mail::later(5,'emails.reminder', ['user' => $user],function ($m) use ($user) {
            $m->from(env('MAIL_FROM'), 'Your Testing Application');
    
            $m->to($user['email'], $user['name'])->subject('Your Reminder!');
        });
    });
    In here we are using Mail::later(5), which represents that email will be sent 5 seconds later. So our setup is done , and if we browse send/mail we will receive email after 5 seconds.

    Laravel 5.2 queuing Event listeners

    First , we need to create Event and to listen event, we also have to create listener. To do this , laravel provides us several ways. The easiest way to create event and corresponding listener we can use this command
    php artisan event:generate
    
    To make it work, we have to define our event and corresponding listener in EventServiceProvider.php. So for test purpose lets provide following values in $listen variable.
    'App\Events\DeleteBranchCourse' => [
                'App\Listeners\DeleteCourseConfirmation',
            ], 
    
    Now we are ready to run our command
    php artisan event:generate
    
    So if we look carefully to Events and Listeners folders, we can see, DeleteBranchCourse and DeleteCourseConfirmation class created respectively. So to make listeners queue , we have to implement ShouldQueue and to manually configure queued jobs, we have to use InteractsWithQueue traits.
    class DeleteCourseConfirmation implements ShouldQueue(){
      use InteractsWithQueue; 
    }
    So to use queue , we have to use database as queue driver. Now we will create a function hello in DeleteBranchCourse Event class and call this function from DeleteCourseConfirmation's handler function
    public function handle(DeleteBranchCourse $event)
        {
    
            $this->attempts($event->hello());
        }
    
    Now we have to fire our event from a controller's function
    Event::fire(new DeleteBranchCourse($feeId));

    Create Your own command on Laravel 5.2


    In Laravel application , when you try this command
     php artisan
    you would see lots of command for laravel application. So if you want to create your own command, laravel provide you very easy way to do this. Here is the command you need.
     php artisan make:console
    To use this command you have to provide a name for the class and you can also provide the name of the command that you want to use in command prompt. So here is the command to make a new command called log:demo
    php artisan make:console LogDemo --command=log:demo
    By running this command, laravel will create a class called LogDemo.class in app/console/commands directory. You can see that there is a protected variable called signature.  
     protected $signature = 'log:demo';
    Here log:demo is the command that you will use on terminal Change the value of description variable as you like. Find handle function and add following line.
    public function handle()
        {
            Log::info('i was here '.Carbon::now());
        }
    
    When you run log:demo command, handle function will be executed. Here this line
    Log::info('i was here '.Carbon::now());
    Will create a line with current time on log file. Which is located on storage/logs directory. Now go to the app/console/kernal.php file. Add this
    'App\Console\Commands\LogDemo',
    string on commands variable. Finally execute php artisan log:demo and this will create a new string on log file. So every time you executed this command, new line will be added on log file.