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

时间:2017-02-02 10:28:11

标签: mongodb laravel-5.4

我收到此错误:

  

Builder.php第485行中的FatalErrorException:

     

调用数组

上的成员函数all()

我的注册控制器

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());
    }
}

1 个答案:

答案 0 :(得分:1)

您需要更新jenssegers/mongodb

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

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

希望这有帮助!