syntax error, unexpected token "<<", expecting "function" or "const"

Viewed 6005

I read this article after upgrading my local dev environment to php8.

And implement it in my class, like:

<<Attribute('foo')>>
public function index()
{
    $posts = (new Post)->get()->withMany('image');

    return $this->app()->view('index', compact('posts'));
}

and it return error.

syntax error, unexpected token "<<", expecting "function" or "const"

What is really a proper of doing that in php8. Am i missing something?

2 Answers
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

    
}
Related