简体   繁体   中英

syntax error, unexpected token "::" when calling "all()" or "get()" in Laravel 8

I'm working on an application that stores information about Esports matches using Laravel 8 and a MySQL server. When generating a simple index page for each of the models by using the "all()" function, they all work perfectly fine except for my "Matches" model. I get the following error message:

syntax error, unexpected token "::", expecting "("

It specifically highlights the first line in the body of the following "index" function in the Matches controller...

public function index()
{
    $matches = Match::get();
    return view('matches.index')->with('matches', $matches);
}

In a slightly strange twist, I only receive this error when the application is deployed to a Heroku server. A local Laravel server does NOT produce this error, everything works perfect!

Maybe Laravel is trying to use an older Model or Controller file?

Let me know if there is anything else I need to share.

Thanks!

Okay, thanks to the guys who replied to my question I've now solved the issue. I did not know Heroku use PHP8 (so that was the first rookie mistake.), Secondly. I had created a model with the same name as a keyword from PHP8 - hence why this problem didn't occur on my local machine running PHP7.

Thanks to all who helped - very much appreciated!

Match is a reserved word in PHP 8 - I had the exact same problem, call your model something like Result instead and remember to rename the file and class name.

public function index()
{
  $matches = Result::get(); // Change from 'Match' which is a reserved word in PHP8
  return view('matches.index')->with('matches', $matches);
}

I did also installed the Contentify eSports CMS while using php 8.0.12 and got the same problem.

This is the link to the work around I did and all the files that I had to modify syntax error, unexpected token "::", expecting"("...app/Modules/MorpheusTheme/Resources/Views/layout.blade.php)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM