Laravel Tutorials
- What is laravel
- Laravel Installation
- Directory Structure
- htaccess
- Remove public from url
- Artisan Command
- Laravel Configuration
- Routing Configuration
- Namespaces
- Request
- Response
- Controller
- Model
- User Authentication
- Multi User Authentication
- Database Seeding
- Database
- Database Query
- ORM
- One-to-One Relationship
- One-to-Many Relationship
- Many to Many Eloquent Relationship
- Has One Through
- Has Many Through
- Querying Relations
- Middleware
- Laravel Views
- Blade Views
- Print data on view page
- Get Site URL
- Get URL Segment
- Get images from Storage folder
- Clear cache
- Form Class not found
- Flash Message in laravel
- Redirections
- path
- CRUD Projerct
- CRUD in Laravel
- CRUD progran
- Laravel Validation
- Jquery Validation
- Cookie
- Session
- Email Send in laravel
- File uploading
- CSRF Protection
- Helper in Laravel
- Helper Functions
- Guzzle Http Client
- Paypal Payment Gatway Integration
- Cron Job in laravel
- Flash message
- path
- Errors Handling
- Date Format
- Date Format Validation
- Display Image on View Page
- Update User Status using toggle button
- Delete Multiple Records using Checkbox in Laravel?
- Confirmation Before Delete Record
- Delete image from storage
- Remove/Trim Empty & Whitespace From Input Requests
- Block IP Addresses from Accessing Website
- How to Disable New User Registration in Laravel
- Redirect HTTP To HTTPS Using Laravel Middleware
- CKEditor
- slug generate unique
- Prevent Browser's Back Button After Logout
- Datatable dunamically
- encrypt & Decript
- Download File
- Rest API
- Shopping Cart
- Shopping Cart Example
- Dynamic Category-Subcategory Menu
- Ajax Search
- Interview Question
- laravel Tutorilal link
- laravel Tutorilal
Important Links
Block IP Addresses from Accessing Website?
Create a Middleware
php artisan make:middleware RestrictIpMiddleware
<?php
namespace App\Http\Middleware;
use Closure;
class RestrictIpMiddleware
{
// set IP addresses
public $restrictIps = ['ip-addr-1', 'ip-addr-2', '127.0.0.1'];
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (in_array($request->ip(), $this->restrictIps)) {
return response()->json(['message' => "You don't have permission to access this website."]);
}
return $next($request);
}
}
Register the Middleware in kernel
protected $middlewareGroups = [
'web' => [
//--------------
\App\Http\Middleware\RestrictIpMiddleware::class,
],
'api' => [
//--------------
],
];
So, our middleware will be checked on every web request.
How to get ip address from request
File name : index.php
$ip = Request::ip();
########### OR #######
$ip = Request::getClientIp(true);
########### OR #######
$ip = request()->ip();
########### OR #######
$ip = $request->ip();
File name : index.php
File name : index.php
File name : index.php