问题
I am getting this error:
FatalErrorException in Builder.php line 485:
Call to a member function all() on array
my register controller
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:
You need to update jenssegers/mongodb
.
Looking at https://github.com/jenssegers/laravel-mongodb the compatability charts shows that 2.3 doesn't satisfy Laravel 5.3+.
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.
Hope this helps!
来源:https://stackoverflow.com/questions/41999722/call-to-a-member-function-all-on-array-in-laravel