我在将本地开发环境升级到php8后阅读了这篇文章。
并在我的课堂上实现它,比如:
<<Attribute('foo')>>
public function index()
{
$posts = (new Post)->get()->withMany('image');
return $this->app()->view('index', compact('posts'));
}
并返回错误。
语法错误,意外的令牌"lt<";,期望";函数";或";const";
在php8中这样做真正合适的地方是什么。我是不是错过了什么?
PHP 8中正确的属性语法是:
#[Attribute('foo')]
https://www.php.net/releases/8.0/en.php
public function create(Request $request)//create object of the request
{
$student = new Student;//create object of the model
$student->name = $request->name;
$student->city = $request->city;
$student->marks = $request->marks;
$student->save();
return redirect('index');//if we write this out of the curly braces then this error show
}