我正在开发laravel 5.4我有3种类型的用户,所有这些用户都很完美,其中一个当然是管理员,另外两个是用户和公司,用户正在使用auth默认登录和注册表格那里这是没有问题,我的问题是公司注册我需要一个新的表格我为公司注册表格制作刀片和注册控制器为他们在app / http / auth文件夹现在表格将加载,当我试图保存从表单中返回此错误:
FatalThrowableError in CompanyRegisterController.php line 54: Type error: Too few arguments to function App\Http\Controllers\Auth\CompanyRegisterController::create(), 0 passed and exactly 1 expected
我的第54行是:
protected function create(array $data)
这是我完整的公司注册控制器:
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class CompanyRegisterController extends Controller
{
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = 'companies';
public function __construct() {
$this->middleware('guest:company');
}
protected function index()
{
return view('auth.company-register');
}
/**
* 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, [
'company_name' => 'required|string|max:255',
'manager_name' => 'required|string|max:255',
'address' => 'required|string|max:255',
'username' => 'required',
'email' => 'required|string|email|max:255|unique:users',
'about' => 'sometimes|min:10|max:2000',
'password' => 'required|string|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return Company::create([
'company_name' => $data['company_name'],
'manager_name' => $data['manager_name'],
'address' => $data['address'],
'username' => $data['username'],
'about' => $data['about'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
更新
我的观看代码
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Companies Register form <span style="float:right;" data-toggle="tooltip" data-placement="top" title="If you need to hire people click here."><a href="#"><i class="fa fa-building"></i> Company register</a></span></div>
<div class="panel-body">
<p>
<img src="{{ asset('images/signup-icon.png') }}" class="img-responsive img-circle regimg" alt="Register" >
</p>
<form class="form-horizontal" role="form" method="POST" action="{{ route('company.register.submit') }}">
{{ csrf_field() }}
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('company_name') ? ' has-error' : '' }}">
<label for="company_name" class="col-md-4 control-label"><i class="fa fa-user-circle"></i> Company Name</label>
<div class="col-md-8">
<input id="company_name" type="text" class="form-control" name="company_name" value="{{ old('company_name') }}" required autofocus>
@if ($errors->has('company_name'))
<span class="help-block">
<strong>{{ $errors->first('company_name') }}</strong>
</span>
@endif
</div>
</div>
</div><!-- end col-md-6 -->
<div class="col-md-6">
<div class="form-group{{ $errors->has('manager_name') ? ' has-error' : '' }}">
<label for="manager_name" class="col-md-4 control-label"><i class="fa fa-user-circle-o"></i> Manager Name</label>
<div class="col-md-8">
<input id="manager_name" type="text" class="form-control" name="manager_name" value="{{ old('manager_name') }}" required autofocus>
@if ($errors->has('manager_name'))
<span class="help-block">
<strong>{{ $errors->first('manager_name') }}</strong>
</span>
@endif
</div>
</div>
</div><!-- end col-md-6 -->
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('address') ? ' has-error' : '' }}">
<label for="address" class="col-md-4 control-label"><i class="fa fa-address-book"></i> Address</label>
<div class="col-md-8">
<input id="address" type="text" class="form-control" name="address" value="{{ old('address') }}" required autofocus>
@if ($errors->has('address'))
<span class="help-block">
<strong>{{ $errors->first('address') }}</strong>
</span>
@endif
</div>
</div>
</div><!-- end col-md-6 -->
<div class="col-md-6">
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label"><i class="fa fa-envelope"></i> E-Mail Address</label>
<div class="col-md-8">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
</div><!-- end col-md-6 -->
</div>
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
<label for="username" class="col-md-4 control-label"><i class="fa fa-birthday-cake"></i> username</label>
<div class="col-md-6">
<input id="username" type="text" class="form-control" name="username" value="{{ old('username') }}" autofocus>
@if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('about') ? ' has-error' : '' }}">
<label for="about" class="col-md-4 control-label"><i class="fa fa-birthday-cake"></i> about</label>
<div class="col-md-6">
<input id="about" type="textarea" class="form-control" name="about" value="{{ old('about') }}" autofocus>
@if ($errors->has('about'))
<span class="help-block">
<strong>{{ $errors->first('about') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label"><i class="fa fa-key"></i> Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label"><i class="fa fa-unlock-alt"></i> Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-success btn-bg btn-block">
<i class="fa fa-registered"></i> Register
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
知道为什么这不起作用?