"ReflectionException Function()不存在"尝试在Laravel中设置身份验证时 [英] "ReflectionException Function () does not exist" when trying to setup authentication in Laravel

查看:45
本文介绍了"ReflectionException Function()不存在"尝试在Laravel中设置身份验证时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使身份验证在Laravel中100%正常工作时遇到了一些麻烦(到目前为止,除"home"外,所有视图似乎都可以正常工作),并希望从那里的Laravel专家那里获得一些帮助.

I'm having some trouble getting authentication working 100% in Laravel (all views seem to work so far except for "home") and was hoping to get some assistance from the Laravel experts out there.

  • PHP版本: 7.3.11
  • Laravel版本: 8.13.0
  • 使用 Composer 来构建ui支架( composer需要laravel/ui )
  • 使用了 Bootstrap ui选项( php artisan ui bootstrap --auth )
  • PHP Version: 7.3.11
  • Laravel Version: 8.13.0
  • Used Composer to build the ui scaffolding (composer require laravel/ui)
  • Used the Bootstrap ui option (php artisan ui bootstrap --auth)

如上所述,到目前为止,我似乎已经可以访问所有生成的身份验证视图(登录,注册和密码重置视图),但是在使用虚拟帐户注册后,尝试访问时出现以下错误家"查看:

As mentioned above, I seem to be able to access all of the generated authentication views so far (login, register & the password reset views), however after registering with a dummy account I get the following error when trying to access the "home" view:

ReflectionException

ReflectionException

函数()不存在

堆栈跟踪指向以下文件:"vendor/laravel/framework/src/Illuminate/Routing/RouteSignatureParameters.php:23":

The Stack trace is pointing to the following file: "vendor/laravel/framework/src/Illuminate/Routing/RouteSignatureParameters.php:23":

<?php

namespace Illuminate\Routing;

use Illuminate\Support\Reflector;
use Illuminate\Support\Str;
use ReflectionFunction;
use ReflectionMethod;

class RouteSignatureParameters
{
    /**
     * Extract the route action's signature parameters.
     *
     * @param  array  $action
     * @param  string|null  $subClass
     * @return array
     */
    public static function fromAction(array $action, $subClass = null)
    {
        $parameters = is_string($action['uses'])
                        ? static::fromClassMethodString($action['uses'])
                        : (new ReflectionFunction($action['uses']))->getParameters();

        return is_null($subClass) ? $parameters : array_filter($parameters, function ($p) use ($subClass) {
            return Reflector::isParameterSubclassOf($p, $subClass);
        });
    }

    /**
     * Get the parameters for the given class / method by string.
     *
     * @param  string  $uses
     * @return array
     */
    protected static function fromClassMethodString($uses)
    {
        [$class, $method] = Str::parseCallback($uses);

        if (! method_exists($class, $method) && Reflector::isCallable($class, $method)) {
            return [];
        }

        return (new ReflectionMethod($class, $method))->getParameters();
    }
}

将以下行(第23行)突出显示为错误:

With the following line (line 23) being highlighted as the error:

:(新的ReflectionFunction($ action ['uses']))-> getParameters();

这是"web.php"中使用的路由文件:

And here are the routes used in the "web.php" file:

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome', ['pageTitle' => 'Home']);
});

Route::get('/services', function () {
    return view('services', ['pageTitle' => 'Services']);
});

Route::get('/contact', function () {
    return view('contact', ['pageTitle' => 'Contact']);
});

Auth::routes();

Route::get('/home', ['pageTitle' => 'Client Dashboard'], [App\Http\Controllers\HomeController::class, 'index'])->name('home');

经过一番谷歌搜索后,我了解到我尝试使用的用于设置身份验证的方法已被弃用,现在建议使用 Jetstream Fortify ,但是我还发现了一些仍在他们的项目中设法使用这种旧方法的人的例子:

After a bit of googling I've learnt that the method I'm trying to use to setup authentication has been deprecated and it is now advised to use Jetstream or Fortify, however I also found a few examples of people still managing to use this old method in their projects:

https://www.youtube.com/watch?v=NuGBzmHlINQ

因为这是我有史以来的第一个Laravel项目,所以我实际上只是在尝试坚持基础知识,而不是让自己变得过于复杂,这就是为什么我选择不使用 Jetstream Fortify ,并尝试坚持使用这种较旧的身份验证方法.但是,我已经在这个问题上停留了两个小时,并且无法弄清楚出了什么问题,这就是为什么我现在正在寻求一些帮助的原因.

As this is my first ever Laravel project I was really trying to just stick with the basics and not over complicate things for myself which is why I chose not to use Jetstream or Fortify and tried to stick to this older approach of setting up authentication. However I've been stuck on this for a couple of hours now and have not been able to figure out what's going wrong which is why I'm now seeking some help with it.

很高兴在需要时提供其他详细信息/项目代码-对此我能提供的任何帮助将不胜感激.

Happy to provide extra details/project code if needed - any help I can get with this would be really appreciated.

顺便说一句,这也是我第一次在StackOverflow上发帖,因此,对我的问题或如何改进它的任何反馈也将不胜感激.

Btw, this also happens to be my first ever post on StackOverflow so any feedback on my question or advice on how I can improve it would also be greatly appreciated.





干杯

adb

推荐答案

通过删除第二个参数(因为它仅包含2个参数),调整您的最后一条路线以包含某种类型的动作":

Adjust your last route to include some type of 'action', by removing that second argument (as it only takes 2 arguments):

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

这篇关于"ReflectionException Function()不存在"尝试在Laravel中设置身份验证时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆