Skip to content

Instantly share code, notes, and snippets.

@Sharifur
Last active July 15, 2022 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sharifur/d5a16fbd7fc93b8e478d78596b4f3e7f to your computer and use it in GitHub Desktop.
Save Sharifur/d5a16fbd7fc93b8e478d78596b4f3e7f to your computer and use it in GitHub Desktop.
block post and put request in laravel using middleware
<?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