How to create manual pagination with search filter in Laravel API?

When you are using To Laravel Project with Connect to Api. Then pagination and search filter (laravel default) will not work in this process. So, you can use DataTable or Manual. So in this blog I am using manual.

This is a Search Input filter

This is Pagination

This is Js in script tag

This is First Laravel Project Controller Function for sending requests for pagination and Search Filter.

This is Second Project Controller Function for pagination and search filter.

Tagged : / / / / /

What is Laravel?

Laravel is a web framework built on PHP. That is the code that has been done by PHP. You can use it to create high-end web applications. That is, you can create a very beautiful web application using variables. The Model View Controller architectural pattern follows the design of Laravel. It is created by Tyler Otwell.

Advance of Laravel

  • Open Source
  • Collection of Tool
  • Save time
  • Improve productivity
  • Robust And Easy
  • Security of the application
  • Authentication
  • Routing
  • Templating

Do You Know?

  • HTML
  • CSS
  • JavaScript
  • SQL
  • PHP OPP
  • MVC
  • Composer

Laravel Requirements

  • PHP 7.2.0 or Higher
  • XAMPP (Apache + MariaDB + PHP + Perl)
  • WAMP/LAMP/MAMP
  • Composer
  • Text/code Editor – Notepad++, vs code, ATOM, Brakets
  • Web Browser – Google Chrome, Mozilla firefox,edge

Tagged : / / / / / /

Multi File upload with Image preview and checklist delete options

In this tutorial i’m going to describe how to upload multiple image with crud operation edit, update delete in laravel. Image upload is necessary of every project. In this project i’m going to learn how to upload with validation like images, mimes, max file upload and etc, with image preview when uploading image and adding features checklist delete.

So let’s go to download project and configure

Please follow some easy steps define below.

First let’s go to install laravel project

composer create-project laravel/laravel admin-dashboard "5.8.*"

After Installation setup database So go to the .env file and add the database credentials. lets go to .env folder and put database name and connect to database.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=admin-dashboard
DB_USERNAME=root
DB_PASSWORD=

Now migrate the table

php artisan migrate

Next step: Add Resource Route Go to your route and paste below code πŸ‘‡πŸ‘‡

use App\Http\Controllers\ProductController;
Route::resource('products', ProductController::class);

Now lets go to create controller, model and migration file go to your terminal and paste below code

php artisan make:model ProductController -mcr

Lets go to your migration file productstable and paste below code. πŸ‘‡

<?phpuse Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;class CreateProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('detail');
$table->string('image');
$table->timestamps();
});
} /**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products');
}
}

Now migrate the table πŸ‘‡πŸ‘‡

php artisan migrate

Next go to Your ProductController file and paste below code πŸ‘‡πŸ‘‡

<?php

namespace App\Http\Controllers;

use App\Product;
use Illuminate\Http\Request;

class ProductController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$products = Product::latest()->paginate(5);

return view('products.index',compact('products'))
->with('i', (request()->input('page', 1) - 1) * 5);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('products.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'name' => 'required',
'detail' => 'required',
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);

$input = $request->all();

if ($image = $request->file('image')) {
$destinationPath = 'image/';
$profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
$image->move($destinationPath, $profileImage);
$input['image'] = "$profileImage";
}

Product::create($input);

return redirect()->route('products.index')
->with('success','Product created successfully.');
}

/**
* Display the specified resource.
*
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function show(Product $product)
{
return view('products.show',compact('product'));
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function edit(Product $product)
{
return view('products.edit',compact('product'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Product $product)
{
$request->validate([
'name' => 'required',
'detail' => 'required'
]);

$input = $request->all();

if ($image = $request->file('image')) {
$destinationPath = 'image/';
$profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
$image->move($destinationPath, $profileImage);
$input['image'] = "$profileImage";
}else{
unset($input['image']);
}

$product->update($input);

return redirect()->route('products.index')
->with('success','Product updated successfully');
}

/**
* Remove the specified resource from storage.
*
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public function destroy(Product $product)
{
$product->delete();

return redirect()->route('products.index')
->with('success','Product deleted successfully');
}


}

Next go to your Model

app/Models/Product.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
protected $fillable =[
'name', 'detail', 'image'
];
}

Now create some file as define below.

Go to your resources/view folder and create following files inside the products folder as define below file like

1) layout.blade.php
2) index.blade.php
3) create.blade.php
4) edit.blade.php
5) show.blade.php

Next go to resouce/view/products/layout file and paste below code

Go to your app.blade.php file and paste below code

<!DOCTYPE html>
<html>
<head>
<title>Multiple Image upload with crud by Laravel Amit</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet">
</head>
<body>

<div class="container">
@yield('content')
</div>

</body>
</html>

Next go to products/index.blade.php and paste below code

@extends('products.layout')
@section('content')
<br><br>
<div class="container" style="margin-right: -50px;">
   <div class="row">
      <div class="col-lg-12 margin-tb">
         <div class="pull-left">
            <h2>Multiple Image upload with crud by Laravel Amit</h2>
         </div>
         <div class="pull-right">
            <a class="btn btn-success" href="{{ route('products.create') }}"> Create New Product</a>
         </div>
      </div>
   </div>
   @if ($message = Session::get('success'))
   <div class="alert alert-success">
      <p>{{ $message }}</p>
   </div>
   @endif
   <table class="table table-bordered">
      <tr>
         <th width="50px"><input type="checkbox" id="master"></th>
         <th>No</th>
         <th>Image</th>
         <th>Name</th>
         <th>Email</th>
         <th>Details</th>
         <th width="280px">Action</th>
      </tr>
      @foreach ($products as $product)
      <tr>
         <td><input type="checkbox" class="sub_chk" data-id="{{$product->id}}"></td>
         <td>{{ ++$i }}</td>
         <td><img src="/image/{{ $product->image }}" width="100px"></td>
         <td>{{ $product->name }}</td>
         <td>{{ $product->email }}</td>
         <td>{{ $product->detail }}</td>
         <td>
            <form action="{{ route('products.destroy',$product->id) }}" method="POST">
               <a class="btn btn-info" href="{{ route('products.show',$product->id) }}">Show</a>
               <a class="btn btn-primary" href="{{ route('products.edit',$product->id) }}">Edit</a>
               @csrf
               @method('DELETE')
               <button type="submit" class="btn btn-danger">Delete</button>
            </form>
         </td>
      </tr>
      @endforeach
   </table>
   {!! $products->links() !!}
</div>
@endsection
Next create files inside the products folder πŸ‘‡πŸ‘‡
create.blade.php

Go to create.blade.php file and paste below code

@extends('products.layout')
@section('content')

<div class="container" style="margin-right: -87px;">
<div class="row">
<div class="col-lg-6">
<div class="pull-left">
<h2>Add New Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('products.index') }}"> Back</a>
</div>
</div>
</div>
<br><br>
@if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif

<form action="{{ route('products.store') }}" method="POST" enctype="multipart/form-data">
@csrf

<div class="row">

<div class="col-md-12">
<div class="form-group">
<input type="file" name="image" placeholder="Choose image" id="image">
@error('image')
<div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
@enderror
</div>
</div>

<!-- <div class="col-md-12 mb-2">
<img id="amit-image-before-upload" src="https://www.riobeauty.co.uk/images/product_image_not_found.gif"
alt="preview image" style="max-height: 250px;">
</div> -->
<!-- preview code testing -->
<div class="col-md-12 mb-2">
<img id="amit-image-before-upload" src="https://www.riobeauty.co.uk/images/product_image_not_found.gif"
alt="preview image" style="max-height: 250px;">
</div>
<!-- preview code test ending -->
<div class="col-lg-12 col-sm-6 col-md-6 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>

</form>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

<script type="text/javascript">

$(document).ready(function (e) {


$('#image').change(function(){

let reader = new FileReader();

reader.onload = (e) => {

$('#amit-image-before-upload').attr('src', e.target.result);
}

reader.readAsDataURL(this.files[0]);

});

});

</script>


@endsection

Next create files inside the products folder πŸ‘‡πŸ‘‡

edit.blade.php

Copy below code and paste edit.blade.php file

@extends('products.layout')

@section('content')
<br><br><br>
<div class="container" style="margin-right: -87px;">
<div class="row">
<div class="col-lg-4 margin-tb">
<div class="pull-left">
<h2>Edit Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('products.index') }}"> Back</a>
</div>
</div>
</div>

@if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif

<form action="{{ route('products.update',$product->id) }}" method="POST" enctype="multipart/form-data">
@csrf
@method('PUT')

<div class="row">
<div class="col-lg-2 col-sm-2 col-md-2">
<div class="form-group">
<strong>Name:</strong>
<input type="text" name="name" value="{{ $product->name }}" class="form-control" placeholder="Name">
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6">
<div class="form-group">
<strong>Email:</strong>
<input type="text" name="name" value="{{ $product->email }}" class="form-control" placeholder="email">
</div>
</div>
<br>
<div class="col-lg-7 col-sm-6 col-md-6">
<div class="form-group">
<strong>Detail:</strong>
<textarea class="form-control" style="height:150px" name="detail" placeholder="Detail">{{ $product->detail }}</textarea>
</div>
</div>
<div class="col-lg-4 col-sm-3 col-md-3">
<div class="form-group">
<strong>Image:</strong>
<input type="file" name="image" class="form-control" placeholder="image">
<img src="/image/{{ $product->image }}" width="300px">
</div>
</div>
<div class="col-lg-4 col-sm-4 col-md-4 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>

</form>
</div>
@endsection

Next create files inside the products folder πŸ‘‡πŸ‘‡

show.blade.php

Copy below code and paste show.blade.php file πŸ‘‡πŸ‘‡

@extends('products.layout')

@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2> Show Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('products.index') }}"> Back</a>
</div>
</div>
</div>

<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
{{ $product->name }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Email:</strong>
{{ $product->email }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Details:</strong>
{{ $product->detail }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Image:</strong>
<img src="/image/{{ $product->image }}" width="500px">
</div>
</div>
</div>
@endsection

Now go to your terminal paste below code

php artisan serve
http://127.0.0.1:8000/products

Now its showing like this

Now you can see before submit the data image preview image showing fine

These steps are implement on my own learning project and looks like this

Thanks i hope its helpfull for you…. πŸ™πŸ™πŸ™ if you have any questions comment below. πŸ™‹πŸ™‹

Tagged : / / /

Laravel : Comparing datetime between two table while selecting record

If you want to Compare datetime between two table while selecting record then,

In this function I am using two table First table using from Controller “AllClassController” in this controller, I am taking all data from $slug, and $id. After that I am taking trainer_email and update_at, after that when get value then Other table using Model “Payment” and using where function and taking “$payments_new” and using foreach function and taking which value who required. Same process for Other “$payments_old”.

This is Output “New Enrolled Students Details” and “Old Enrolled Students Details”.

Tagged : / / / /

Syntax ERROR: A non well formed numeric value encountered

When you using @foreach value in a variable in your blade file and put any value and using any Mathematics function in your value for showing your document this type of error.

 @foreach($allcourses as $i => $allclass)

	<p>{{$allclass['total_fees_of_class']}}</p>
            <?php 
                        $fee = $allclass['total_fees_of_class']; 
                        $c = ($fee);
                        $a = (100);
                        $d = (20);
                        $e = $c * $d / $a;
                        $fee = $c + $e;
           ?>

               <span>
               		<b>{{$fee}}</b>
               </span>
@endforeach

Then, You can add (int) as prefix in your foreach value as “$c = (int)($fee);” and write as below code

               <?php 
                    $fee = $allclass['total_fees_of_class']; 
                    $c = (int)($fee);
                    $a = (100);
                    $d = (20);
                    $e = $c * $d / $a;
                    $fee = $c + $e;
               ?>

Your program will run.

Tagged : / / / /

How to Upload Multiple Image in Laravel

In this turoial im going to learn how to upload multiple image in laravel and store in database. Image upload is necessary of every project. In this project i’m going to learn how to upload with validation like images, mimes, max file upload and etc.

So let’s go to download project and configure with database. so copy below code and paste in your terminal.

First let’s go to install laravel project

composer create-project laravel/laravel admin-dashboard "5.8.*"

After Installation setup database So go to the .env file and add the database credentials. lets go to .env folder and put database name and connect to database.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=admin-dashboard
DB_USERNAME=root
DB_PASSWORD=

Now migrate the table

php artisan migrate

Lets go to create migration file to store the image name go to your terminal and paste below code.

php artisan make:migration create_forms_table

Let’ go to migration table and add file name.

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateFormsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('forms', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('filename');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('forms');
}
}

The next step will be to migrate this schema and make a table in the database.

php artisan migrate

Next go to create the controller and model file for this project copy below code and paste in your command. πŸ‘‡πŸ‘‡

php artisan make:model Form

php artisan make:controller FormController

lets got to setup the model and controller file for our project.

Step 2: Define routes in the web.php file.

copy below code and paste in your route/web.php file πŸ‘‡

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::get('form','FormController@create');
Route::post('form','FormController@store');

Go to your controller and paste below code in your controller πŸ‘‡

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Form;

class FormController extends Controller
{
public function create()
{
return view('create');
}

public function store(Request $request)
{
$this->validate($request, [
'filename' => 'required',
'filename.*' => 'image | mimes:jpeg,png,jpg,gif,svg|max:2048'
]);

if($request->hasfile('filename'))
{
foreach($request->file('filename') as $image)
{
$name=$image->getClientOriginalName();
$image->move(public_path().'/images',$name);
$data[] =$name;
}
}

$form= new Form();
$form->filename=json_encode($data);

$form->save();

return back()->with('success', 'image has been successfully updated');
}


}

Now, let us make a create.blade.php file inside the Resources/views folder.

@extends('layouts.app')
@section('content')


<div class="container">
@if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif

@if(session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif

<h3 class="jumbotron">Laravel Multiple File Upload</h3>
<form method="post" action="{{url('form')}}" enctype="multipart/form-data">
{{csrf_field()}}

<div class="input-group control-group increment" >
<input type="file" name="filename[]" class="form-control">
<div class="input-group-btn">
<button class="btn btn-success" type="button"><i class="glyphicon glyphicon-plus"></i>Add</button>
</div>
</div>
<div class="clone hide">
<div class="control-group input-group" style="margin-top:10px">
<input type="file" name="filename[]" class="form-control">
<div class="input-group-btn">
<button class="btn btn-danger" type="button"><i class="glyphicon glyphicon-remove"></i> Remove</button>
</div>
</div>
</div>

<button type="submit" class="btn btn-primary" style="margin-top:10px">Submit</button>

</form>
</div>


<script type="text/javascript">


$(document).ready(function() {

$(".btn-success").click(function(){
var html = $(".clone").html();
$(".increment").after(html);
});

$("body").on("click",".btn-danger",function(){
$(this).parents(".control-group").remove();
});

});

</script>

@endsection

Now let’s go to your browser and paste below code πŸ‘‡

http://127.0.0.1:8000/form

Now image has been successfully added in database as well. πŸ‘‡

Thanks i hope its helpfull for you. πŸ™πŸ™πŸ™Amit Kumar

Hi I am Amit Experienced Web Developer with a demonstrated history of working in the information technology and services industry.

Tagged : / / / /

How to Add Google reCAPTCHA on Register page and login page in Laravel

In this tutorial I’m going to learn how to add captcha features in on register blade and login page. Nowadays captcha is very useful because its very important for security reason.

There are several library to generate captcha image in Laravel. In this example I’m going to use Google reCaptcha for generate captcha using anhskohbo/no-captcha package. anhskohbo/no-captcha is very popular package.

Please follow some easy steps define below….

First let’s go to install laravel project

composer create-project laravel/laravel admin-dashboard "5.8.*"

Setup database with your installed laravel 8 project . πŸ‘‡ Step 2 β€” Database Configuration

lets go to .env folder and put database name and connect to database.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=admin-dashboard
DB_USERNAME=root
DB_PASSWORD=

Now migrate the table

php artisan migrate

Now Create Auth

php artisan make:auth

Next step we have to install anhskohbo/no-captcha package for Google reCaptcha code, after install these package we able to generate captcha code in our register and login page. copy below code and paste in your terminal

composer require anhskohbo/no-captcha

Next add below code in provider path in config/app.php path

Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::class,

Next Set Google Site Key

Now go to set google secret key and google site key. if you are new user then you have to create from here. go through below link

Recaptcha Admin

After submit this form you’ll get site key and secret key

Now go to .env file and add this two variable

.env

#########Google Recaptcha
 NOCAPTCHA_SITEKEY=your site key
 NOCAPTCHA_SECRET=your secret key

Next go to Route/web.php and add Auth::routes();

Auth::routes();

Go to Route/web.php

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Next go to RegisterController.php and add this class

RegisterController.php

'g-recaptcha-response' => 'required|captcha',

Next go to App.blade.php and add below script

App.blade.php

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
{!! NoCaptcha::renderJs() !!}

And last step of the go to register.blade.php file and add google captcha code before the register button

register.blade.php

<div class="form-group row {{ $errors->has('g-recaptcha-response') ? ' has-error' : '' }} ">
<label for="captcha" class="col-md-4 col-form-label text-md-right">{{ __('captcha') }}</label>

<div class="col-md-3" style="">
{!! app('captcha')->display() !!}
@if ($errors->has('g-recaptcha-response'))
<span class="help-block">
<strong>{{ $errors->first('g-recaptcha-response') }}</strong>
</span>
@endif
</div>
</div>

Now refresh your browser and you can see google captcha code successfully added in your register page.

http://127.0.0.1:8000

Successfully Login

I hope this tutorial is helpful for you… if you have any question comment now. πŸ™πŸ™

Tagged : / / /

Not Found The requested URL was not found on this server.

Apache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.2.34 Server at ds-student-ms Port 80

In this tutorial I’m going to describe how to solve this error

Not Found The requested URL was not found on this server Apache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.2.34 Server at ds-student-ms Port 80.

I got a error when i created virtual host and when i Open in browser its showing Not found the requested url.

I tried lots of then i got what’s the error on my project Simply go to your project directory

C:\xampp\htdocs\ds-student-ms\public\.htaccess

Simply open this file in editor and paste below code.

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>

RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Now refresh your browser and you can see its open correctly

Thanks its helpful for you.

Tagged : / / /

How to Send Email when someone Register and also send email verification

In this tutorial I’m going to describe how to get email verification when someone register in laravel. Please follow some easy steps mentioned below.

First let’s go to install laravel project

composer create-project laravel/laravel mail-verification "5.8.*"

πŸ‘‡ Database Configuration

Setup database with your installed laravel 8 project . lets go to .env folder and put database name and connect to database.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel-mail
DB_USERNAME=root
DB_PASSWORD=

Next click on create

Next set up to mail trap for getting mail

Go to this URL β€” MailTrapio

Go to .env and put your mailtrap credentials

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=puthere-----
MAIL_PASSWORD=puthere-----
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

Now migrate the table

php artisan migrate

Now Create Auth

php artisan make:auth

Go to App/user.php file and paste below code

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements MustVerifyEmail
{
use Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}

Next go to Set-up Routes

Routes/web.php

Replace Auth:Routes to below code

Auth::routes(['verify' => true]);

Next go to HomeController.php file and paste below function code

public function __construct()
{
$this->middleware(['auth', 'verified']);
}

Now set-up is completed run below code

php artisan serve

Now page is look like this

Now you got successfully got verification email

Now also you’ll get email when register

Login successfully when you verify email

Thanks i hope its helpful for you πŸ™πŸ™

Tagged : / / /

How to Manual filter table and search in ajax, laravel framework

Step 1: defied blade file input this code

Step 2: defied blade file script part input this code

Step 3: defied routes file web.php part file input this code this is route

Step 4: defied Controller file CategoryController part file input this code this is function

Tagged : / /