Last active
July 15, 2022 04:26
-
-
Save Sharifur/d5a16fbd7fc93b8e478d78596b4f3e7f to your computer and use it in GitHub Desktop.
block post and put request in laravel using middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Support\Str; | |
class Demo | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
$not_allow_path = [ | |
'admin-home', | |
'user-home' | |
]; | |
$allow_path = [ | |
'admin-home/visited/os', | |
'admin-home/visited/browser', | |
'admin-home/visited/device', | |
'admin-home/visited-url', | |
'admin-home/media-upload/all', | |
'admin-home/media-upload/loadmore' | |
]; | |
$contains = Str::contains($request->path(), $not_allow_path); | |
if($request->isMethod('POST') || $request->isMethod('PUT')) { | |
if($contains && !in_array($request->path(),$allow_path)){ | |
if ($request->ajax()){ | |
return response()->json(['type' => 'warning' , 'msg' => 'This is demonstration purpose only, you may not able to change few settings, once your purchase this script you will get access to all settings.']); | |
} | |
return redirect()->back()->with(['type' => 'warning' , 'msg' => 'This is demonstration purpose only, you may not able to change few settings, once your purchase this script you will get access to all settings.']); | |
} | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment