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 : / / /

302 Found: What It Is and How to Fix It?

What is 302 status?

The HTTP response status code 302 Found is a common way of performing URL redirection. A 302 Found message is an HTTP response status code indicating that the requested resource has been temporarily moved to a different URI. All HTTP response status codes that are in the 3xx category are considered redirection messages.

Diagnosing a 302 Found Response Code

itโ€™s entirely possible that the server is misconfigured, causing it to improperly respond with 302 Found codes, instead of the standard and expected 200 OK code of a normal, functional request.

If your application is responding with 302 Found codes, this is an issue that many other visitors may be experiencing as well, dramatically hindering your applicationโ€™s ability to service users.

if you want to dig out on above topic then follow below references :

By ClickMinded

so friends here I am describing all above things for understanding about 302. because i am facing this issue in my Laravel application so let’s check out to solve these issues in your Laravel application. below is the attached urls for common issue in Laravel related to 302.

References :

  1. Click Here
  2. Click Here
  3. Click Here
Tagged : / / / / / /

Laravel 8 Form Example Tutorial

In this tutorial iโ€™m going to describe to create form and store data in database. Please follow some easy steps mentioned below.

How to Submit Form Data into Database in Laravel 8

  • Step 1 โ€” Install Laravel 8 Application
  • Step 2 โ€” Configuring Database using Env File
  • Step 3 โ€” Create Model & Migration File For Add Blog Post Form
  • Step 4 โ€” Create Routes
  • Step 5 โ€” Creating Controller
  • Step 6 โ€” Create Blade File For Add Blog Post Form
  • Step 7 โ€” Start Development Server
  • Step 8 โ€” Run Laravel 8 Form App On Browser

Step 1 โ€” Install Laravel 8 Application

composer create-project laravel/laravel laravelform
  • Step 2 โ€” Configuring Database using Env File

Now create model and migration table

php artisan make:model Post -m

Next go to post migration table and paste below code

<?php

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

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

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

Next go to Post model and paste below code

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
protected $fillable=[
'title',
'description'
];
}

Now migrate the table run below command

php artisan migrate

Step 4 โ€” Create Routes

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| 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');
});

Route::get('add-blog-post-form', [PostController::class, 'index']);
Route::post('store-form', [PostController::class, 'store']);

Step 5 โ€” Creating Controller

php artisan make:controller PostController -r

Go to your Post controller file and paste below code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;use App\Post;class PostController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('add-blog-post-form');
}

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

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$post = new Post;

$post->title = $request->title;
$post->description = $request->description;

$post->save();

return redirect('add-blog-post-form')->with('status', 'Blog Post Form Data Has Been inserted');
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}

Step 6 โ€” Create Blade File For Form

add-blog-post-form.blade.php

Go to Resources/views/add-blog-post-form.blade.php and create this file

<!DOCTYPE html>
<html>
<head>
<title>Laravel 8 Form Example Tutorial laravel Amit</title>
<meta name="csrf-token" content="{{ csrf_token() }}">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

</head>
<body>

<div class="container mt-4">

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

<div class="card">
<div class="card-header text-center font-weight-bold">
Laravel 8 - Add Blog Post Form Example
</div>
<div class="card-body">
<form name="add-blog-post-form" id="add-blog-post-form" method="post" action="{{url('store-form')}}">
@csrf

<div class="form-group">
<label for="exampleInputEmail1">Title</label>
<input type="text" id="title" name="title" class="form-control" required="">
</div>

<div class="form-group">
<label for="exampleInputEmail1">Description</label>
<textarea name="description" class="form-control" required=""></textarea>
</div>

<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</body>
</html>

Now refresh the Browser

php artisan serve

When you fire the above given url on browser, you will look like in the following image:

http://127.0.0.1:8000/add-blog-post-form

Thanks

Tagged : / / /

Laravel Error:Integrity constraint violation

yesterday : when i am trying to submit data to store in database i got error integrity constraint violation rule

because role_id is foreign key and i did not mention this field in user model.

Solution: after role_id mention in user model my error got solved

https://gist.github.com/rakesh1166-cm/6e233a6d0f51504801713420cb483338#file-users-php

Tagged :

Target class [PostController] does not exist.

Whenever you got this types of error go to your Route/web.php file and checkout your Controller class is mention there or not.

Next Go to PostController file and copy your controller class

Now go to Routes/web.php and class this class

use App\Http\Controllers\PostController;
php artisan serve

Now its working properly

Thanks.

Tagged : / / / /

Crud Operation in Laravel with Image Store laravel 5.8

In this tutorial I’m going to describe about crud operation how to install project and setup and create controller, models, migration and all the things please read it carefully and follow some easy steps.

Lets go to download project and set up to

composer create-project laravel/laravel form "5.8.*"

Next go to .env file and put your database name -> form

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=form
DB_USERNAME=root
DB_PASSWORD=

Next step create database in PhpMyAdmin Database name ๐Ÿ‘‡

form

Now migrate the table run this command ๐Ÿ‘‡

php artisan migrate

Table has been migrated successfully.

letโ€™s go to create model, migration and controller in one command copy below code and paste in your terminal.

php artisan make:model product -mcr

Now migrate the table

php artisan migrate

Step 4: Add Resource Route

<?php

use App\Http\Controllers\ProductController;


/*
|--------------------------------------------------------------------------
| 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');
});


// Route::resource('products', ProductController::class);

Route::resource('products', ProductController::class);

Step 5: Go to Your Controller and paste below code in your controller file

<?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',
'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 model and paste in below code

app/Models/Product.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

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

Step 6: Add Blade Files

1) layout.blade.php

2) index.blade.php

3) create.blade.php

4) edit.blade.php

5) show.blade.php

resources/views/products/layout.blade.php

<!DOCTYPE html>
<html>
<head>
<title>Laravel Crud Operation 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>

resources/views/products/index.blade.php

@extends('products.layout')

@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Laravel Crud Operation with Image store 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>No</th>
<th>Image</th>
<th>Name</th>
<th>Details</th>
<th width="280px">Action</th>
</tr>
@foreach ($products as $product)
<tr>
<td>{{ ++$i }}</td>
<td><img src="/image/{{ $product->image }}" width="100px"></td>
<td>{{ $product->name }}</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() !!}

@endsection

resources/views/products/create.blade.php

@extends('products.layout')

@section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<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>

@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-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
<input type="text" name="name" class="form-control" placeholder="Name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Detail:</strong>
<textarea class="form-control" style="height:150px" name="detail" placeholder="Detail"></textarea>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Image:</strong>
<input type="file" name="image" class="form-control" placeholder="image">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>

</form>
@endsection

resources/views/products/edit.blade.php

@extends('products.layout')

@section('content')
<div class="row">
<div class="col-lg-12 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-xs-12 col-sm-12 col-md-12">
<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-xs-12 col-sm-12 col-md-12">
<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-xs-12 col-sm-12 col-md-12">
<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-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>

</form>
@endsection

resources/views/products/show.blade.php

@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>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 php artisan serve

http://localhost:8000/products

Now its open look like this ๐Ÿ‘‡

Thanks ๐Ÿ™๐Ÿ™

Tagged : / / / /

Top 10 Interview Question in Laravel 2021?

Q #1) What is Laravel?.

Laravel is a free and open-source PHP framework that is utilized to developed wide variety of web applications. Laravel is an accessible language for new programmers because the laravel community provides lots of modules resources are free available. Laravel provides a simple way to authorization logic and control access to resources with a simple ActiveRecord implementation that makes their interaction with databases.

Q #2) Define Composer.

Composer is a dependency manager for php framework. Composer runs through the command line. The main purpose of the composer is to install the dependencies or libraries for an application. Composer help to install required package component whatever you want to install in your application.

Q #3) What is Routing?

Route is a way to create request URL of your application, Route is a method of accepting a request and sending it to the relevant function in the controller.

What are the two main routing files in Laravel?

1. web.php
2. api.php

Q #4) What is a CSRF token?

Answer: CSRF is an abbreviation for Cross-Site Request Forgery that is generated by the server-side application and transmitted to the client. A CSRF token is a unique value that is generated by the server-side of the application and sent to the client

CSRF token helps to protect web applications from attacks which force a user to perform an unwanted action (commonly known as CSRF attacks).

Q #5) What is an artisan?

Artisan is the command-line tool for Laravel to help the developer build the application use while developing your application. You can enter the below command to get all the available commands:

example of commands

php artisan make:controller โ€” Make Controller file
php artisan make:model

Q #6) How to put Laravel applications in maintenance mode?

php artisan down

And can put the application again on live using the below command:

php artisan up

Q #7) How to put Laravel applications in maintenance mode?

What are the default route files in Laravel?

web.php โ€” For registering web routes.
api.php โ€” For registering API routes.
console.php โ€” For registering closure-based console commands.
channel.php โ€” For registering all your event broadcasting channels that your application supports.

Q #8) What are seeders in Laravel?

Seeders in laravel are used to put dummy data in the database tables automatically. After running migrations to create the tables, we can run `php artisan db:seed` to run the seeder to populate the database tables.

We can create a new Seeder using the below artisan command:

php artisan make:seeder [className]

Q #9) List out common artisan commands used in Laravel.

Laravel supports following artisan commands:

PHP artisan down;
PHP artisan up;
PHP artisan make:controller;
PHP artisan make:model;
PHP artisan make:migration;
PHP artisan make:middleware;

Q #10) What is the Latest version of Laravel?

Answer: Laravel 8 is the latest version.

Thanksโ€ฆ ๐Ÿ‘๐Ÿ‘

Tagged : / / / / /

Laravel 5.5 Method paginate does not exist

When I am trying to put some value in my input search box and after pressing enter button showing above issue.
But when I am trying to filter data with my search button then it’s working fine. so i dig into it. i found one solution on it.

FilterController.php
$users = DB::table('users')
->where(function($query) use ($countryId, $stateId, $cityId) {
	if (isset($countryId) && $countryId !== null && $countryId !== '' && $stateId == 'Select State') {
		$query->where('country_id', '=', $countryId);
	}
	if (isset($countryId) && $countryId !== null && $countryId !== '' && isset($stateId) && $stateId !== 'Select State' && $stateId !== '') {
		$query->where([
							['country_id', '=', $countryId],
							['state_id', '<>', $stateId]
						]);
		
	}
})->get()->paginate(5);

Solution :

Just remove the get() and your code will work fine.

$users = DB::table('users')
->where(function($query) use ($countryId, $stateId, $cityId) {
	if (isset($countryId) && $countryId !== null && $countryId !== '' && $stateId == 'Select State') {
		$query->where('country_id', '=', $countryId);
	}
	if (isset($countryId) && $countryId !== null && $countryId !== '' && isset($stateId) && $stateId !== 'Select State' && $stateId !== '') {
		$query->where([
							['country_id', '=', $countryId],
							['state_id', '<>', $stateId]
						]);
		
	}
})->paginate(5);

References :

  1. Click here
  2. Click here
Tagged : / /