为啥我的 Laravel 应用程序会出现 ParseError? [关闭]
Posted
技术标签:
【中文标题】为啥我的 Laravel 应用程序会出现 ParseError? [关闭]【英文标题】:Why do I get a ParseError in my Laravel app? [closed]为什么我的 Laravel 应用程序会出现 ParseError? [关闭] 【发布时间】:2022-01-24 04:14:38 【问题描述】:错误如下。我真的不知道如何解决它:
解析错误 语法错误,意外的 '@',期待函数 (T_FUNCTION) 或 const (T_CONST)
代码:
<?php
namespace App\Http\Controllers\Auth;
use App\Setting;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ResetsPasswords;
class ResetPasswordController extends Controller
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Where to redirect users after resetting their password.
*
*
*/
@var string
protected $redirectTo = RouteServiceProvider::HOME;
public function __construct()
if(Auth::check() && Auth::user()->role_id == 1)
$this->redirectTo = route('admin.dashboard');
elseif(Auth::check() && Auth::user()->role_id == 2)
$this->redirectTo = route('user.dashboard');
$this->middleware('guest')->except('logout');
protected function redirectTo()
return '/user/dashboard';
public function showResetForm($token)
$config = DB::table('config')->get();
$settings = Setting::first();
$google_configuration = [
'GOOGLE_ENABLE' => env('GOOGLE_ENABLE', ''),
'GOOGLE_CLIENT_ID' => env('GOOGLE_CLIENT_ID', ''),
'GOOGLE_CLIENT_SECRET' => env('GOOGLE_CLIENT_SECRET', ''),
'GOOGLE_REDIRECT' => env('GOOGLE_REDIRECT', '')
];
$settings['google_configuration'] = $google_configuration;
return view('auth.passwords.reset',compact('config', 'token', 'settings'));
【问题讨论】:
【参考方案1】:问题是@var string
,所以尝试删除它
【讨论】:
已修复,非常感谢您的快速帮助 :)【参考方案2】:@var string
在顶部
protected $redirectTo = RouteServiceProvider::HOME;
不应该在评论里面吗?
【讨论】:
【参考方案3】:这一行:
@var string
是一个phpDoc 属性(用于解释代码),不知何故已从其上方的注释块中删除。
像这样把它移回评论区:
/**
* Where to redirect users after resetting their password.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
【讨论】:
【参考方案4】:你不小心再次取消评论,让它成为评论
@var string
【讨论】:
以上是关于为啥我的 Laravel 应用程序会出现 ParseError? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章
为啥 Owl Carousel 在我的 Laravel 应用程序中会破坏引导模式?
当我尝试使用 Laravel 控制器方法处理 AJAX 请求时,为啥会出现此异常?