【问题标题】: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'));
    }

}

【问题讨论】:

    标签: php laravel


    【解决方案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
        

        【讨论】:

          猜你喜欢
          • 2019-04-13
          • 2015-10-03
          • 2016-06-23
          • 1970-01-01
          • 1970-01-01
          • 2019-11-27
          • 2016-09-28
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多