Php 拉维碳
我有这个问题。当我创建新的中间件并编写此代码时 这是一个错误文本语法错误、意外的“printf”(T_字符串)、预期函数(T_函数)或常量(T_常量)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
在类的函数外不能有这样的语句
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)
}