Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 拉维碳_Php_Laravel_Package_Laravel 8 - Fatal编程技术网

Php 拉维碳

Php 拉维碳,php,laravel,package,laravel-8,Php,Laravel,Package,Laravel 8,我有这个问题。当我创建新的中间件并编写此代码时 这是一个错误文本语法错误、意外的“printf”(T_字符串)、预期函数(T_函数)或常量(T_常量) 在类的函数外不能有这样的语句 namespace-App\Http\Middleware; 使用碳\碳; 使用闭包; 使用\Http\Request; 课堂检查时间 { 公共函数句柄(请求$Request,关闭$next) { printf(“现在是%s”,Carbon::now()->toDateTimeString()); $now=碳::n

我有这个问题。当我创建新的中间件并编写此代码时

这是一个错误文本语法错误、意外的“printf”(T_字符串)、预期函数(T_函数)或常量(T_常量)


在类的函数外不能有这样的语句

namespace-App\Http\Middleware;
使用碳\碳;
使用闭包;
使用\Http\Request;
课堂检查时间
{
公共函数句柄(请求$Request,关闭$next)
{
printf(“现在是%s”,Carbon::now()->toDateTimeString());
$now=碳::now();
$start=Carbon::createFromTimeString('00:00');
$end=Carbon::createFromTimeString('06:00');
如果($now->between($start,$end)){
return redirect(“/”)->带有('limitTime,此时不能写文章');
}
返回$next($request);
}
}

您不能在类中的方法(函数)之外输出任何内容或执行操作。。将所有代码放入
handle()
方法中。
namespace App\Http\Middleware;
use Carbon\Carbon;
use Closure;
use Illuminate\Http\Request;

class CheckTime
{
    printf("Right now is %s", Carbon::now()->toDateTimeString());

    // $now = Carbon::now();
    // $start = Carbon::createFromTimeString('00:00');
    // $end = Carbon::createFromTimeString('06:00');


    if ($now->between($start, $end)) {
        return redirect('/')->with('limitTime, You cant write post at this time');
    }

    return $next($request);
    public function handle(Request $request, Closure $next)
}