在laravel中的数组上调用成员函数all() [英] Call to a member function all() on array in laravel

查看:35
本文介绍了在laravel中的数组上调用成员函数all()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

Builder.php第485行中的FatalErrorException:

FatalErrorException in Builder.php line 485:

在数组上调用成员函数all()

Call to a member function all() on array

我的注册控制器

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;


class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'fullname' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        
        return User::create([
            'name' => $data['fullname'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }

    /**
     * Handle a registration request for the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function register(Request $request)
    {
        $validator = $this->validator($request->all());

        if ($validator->fails()) {
            $this->throwValidationException(
                $request, $validator
            );
        }
        $user = $this->create($request->all());
        

        return redirect($this->redirectPath());
    }
}

推荐答案

您需要更新 jenssegers/mongodb .

查看 https://github.com/jenssegers/laravel-mongodb 的兼容性图表显示2.3不满足Laravel 5.3 +.

Looking at https://github.com/jenssegers/laravel-mongodb the compatability charts shows that 2.3 doesn't satisfy Laravel 5.3+.

得到该特定错误的原因是因为在Laravel 5.3中对查询生成器进行了更改,因此它将返回一个集合而不是数组,但是, jenssegers/mongodb 的版本为2.3只是返回一个数组.在 jenssegers/mongodb 的 3.1 版中,现在可以检查以确定您为此使用的 Laravel 版本.

The reason you're getting that specific error is because in Laravel 5.3 a change was made to the query builder so it would return a collection instead of an array, however, 2.3 of jenssegers/mongodb just returns an array. In version 3.1 of jenssegers/mongodb there is now a check to determine which version of Laravel you're using for this reason.

希望这会有所帮助!

这篇关于在laravel中的数组上调用成员函数all()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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