*1.用户在在指定的时间里发送了太多的请求。用于限制速率。可以用于做访问限制模块
//定义中间路由
Route::middleware('throttle:login')->group(function (){
Route::get('login',[LoginController::class,'login']);Route::get('logindo',[LoginController::class,'loginDo']);
});
perminute里的参数是对应的访问频率限制
2.注册中间件 在kernel定义好中间件就可以用来中间件拦截了
Route::group(['prefix'=>'wechat','namespace'=>'Api','middleware'=>'checklogin'],function (){
Route::get('login',[LoginController::class,'login']);Route::get('logindo',[LoginController::class,'loginDo']);
});
<?php
class Mysql{
private static $mysql=null;private function __clone(){
// TODO: Implement __clone() method.}private function __construct(){
}//入口public static function concent(){
if (self::$mysql===null){
try {
self::$mysql=mysqli_connect('主机号','账户','密码','库名');}catch(\Exception $e){
return ['连接失败'.$e->getMessage()];}}if (!self::$mysql instanceof self){
try {
self::$mysql=mysqli_connect('主机号','账户','密码','库名');}catch(\Exception $e){
return ['连接失败'.$e->getMessage()];}}return self::$mysql;}
}var_dump($obj=Mysql::concent('主机号','账户','密码','库名'));