Answers for "laravel get ip from request([])"

PHP
0

laravel denny request by ip

//Run:
//php artisan make:middleware IpMiddleware

<?php

namespace App\Http\Middleware;

use Closure;

class IpMiddleware
{

    public function handle($request, Closure $next)
    {
        if ($request->ip() != "192.168.0.155") {
        // here instead of checking a single ip address we can do collection of ips
        //address in constant file and check with in_array function
            return redirect('home');
        }

        return $next($request);
    }

}
// END OF FILE

// ---------------------
// app/Http/Kernel.php
//then add the new middleware class in the $middleware property of your app/Http/Kernel.php class.

protected $routeMiddleware = [
    //... other middlewares
    'ipcheck' => \App\Http\Middleware\IpMiddleware::class,
];
// ------------------
///In your route
then apply middelware to routes

Route::get('/', ['middleware' => ['ipcheck'], function () {
    // your routes here
}]);
Posted by: Guest on December-17-2020
0

laravel get data from request

dd($request->all());
//print an array of the input name and the input value
Posted by: Guest on July-04-2020

Code answers related to "laravel get ip from request([])"

Browse Popular Code Answers by Language