2017-03-21 36 views
1

我有此鏈接:語法錯誤並不在localhost

​​

和這條路線:

Route::get('/list', '[email protected]'); 

控制器的方法:

public function list() 
    { 
     $users=User::orderBy('district_involved')->get(); 
     return view('list')->with('users',$users); 
    } 

但是,我得到了語法錯誤:

syntax error, unexpected 'list' (T_LIST), expecting identifier (T_STRING)

這適用於本地主機,但不在服務器上。

+0

錯誤消息是否指定語法錯誤所在的文件? –

+0

@RossWilson是在這個確切的方法在控制器。 – Steve

+0

你的意思是你只在生產服務器上得到這個錯誤,而不是在你的本地環境中? – Amarnasan

回答

2

很可能你的localhost正在運行5.6.4>並且你的web服務器正在運行7. *。

在php 7中,列表方法不可用。如果您使用PHPStorm,您會得到一個通知,list是PHP 7(或更新版本)中的一種新方法。看一看:http://php.net/manual/en/function.list.php#refsect1-function.list-changelog

我會建議你改變你的方法:

public function listUsers() 
{ 
    $users=User::orderBy('district_involved')->get(); 
    return view('list')->with('users',$users); 
} 

Route::get('/list', '[email protected]');