2017-04-18 3 views
1

私はレジスタとログイン機能を実装しようとしています。 私が使っているプロジェクトには、すでにいくつかのデフォルトモデルと認証コントローラがあります。Laravel 5.4 - 内部エラー:デフォルト値の取得に失敗しました

App/User.php 
App/Http/Controllers/Auth/RegisterController.php 
App/Http/Controllers/Auth/LoginController.php 

私はこれらのファイルのすべてにusernamenameを変更しました。

ルート

Route::get('/',    function() { return view('welcome'); }); 
Route::get('main',    function() { return view('mainmenue'); }); 
Route::get('login',        'Auth\[email protected]'); 
Route::get('register',       'Auth\[email protected]'); 
Route::post('register/post',     'Auth\[email protected]'); 
Route::post('login/post',      'Auth\[email protected]'); 
Route::get('logout',       'Auth\[email protected]')->middleware("auth"); 

アプリケーション/ User.php

<?php 

namespace App; 

use Illuminate\Notifications\Notifiable; 
use Illuminate\Foundation\Auth\User as Authenticatable; 

class Users extends Authenticatable 
{ 
    use Notifiable; 

    /** 
    * The attributes that are mass assignable. 
    * 
    * @var array 
    */ 
    protected $fillable = [ 
     'username', 'password', 
    ]; 

    /** 
    * The attributes that should be hidden for arrays. 
    * 
    * @var array 
    */ 
    protected $hidden = [ 
     'password', 'remember_token', 
    ]; 
} 

アプリケーション/ HTTP /コントローラ/認証/ RegisterController.php

<?php 

namespace App\Http\Controllers\Auth; 

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

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 = '/login'; 

    /** 
    * 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, [ 
      'username' => 'required|max:255', 
      'password' => 'required|min:6|confirmed', 
     ]); 
    } 

    /** 
    * Create a new user instance after a valid registration. 
    * 
    * @param array $data 
    * @return Users 
    */ 
    protected function create(array $data) 
    { 

     return User::create([ 
      'username' => $data['username'], 
      'password' => bcrypt($data['password']), 
     ]); 
    } 

    /** 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function show() 
    { 
     return view('auth/register'); 
    } 
} 

登録ビュー

<form id="store" class="center" method="POST" action="{{url("register/post")}}" enctype="multipart/form-data"> 

     {{ csrf_field() }} 

     <table> 
      <col width="130"> 
      <col width="80"> 
      <tr> 
       <td>Benutzername:</td> 
       <td><input type="text" class="form-control" id="username" name="username" value=""></td> 
      </tr> 
      <tr> 
       <td>Password:</td> 
       <td><input type="password" class="form-control" id="password" name="password" value=""></td> 
      </tr> 
      <tr> 
       <td>Password nochmal eingeben:</td> 
       <td><input type="password" class="form-control" id="password_confirmation" name="password_confirmation" value=""></td> 
      </tr> 
     </table> 

     <div class="form-group"> 
      <button type="submit" class="btn btn-default">Registrieren</button> 
     </div> 

     @include('../partials.errors') 

    </form> 

私はマイグレーションを使用し、手でテーブルusersを作成していませんでした。

enter image description here

しかし、私が手の形提出後:私は提出する前に何かを入力するか、または空のそれを送信する場合

Whoops, looks like something went wrong. 1/1 ReflectionException in /opt/lampp/htdocs/selenium/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php line 57: Internal error: Failed to retrieve the default value

をそれはメイザー、エラーが常に表示されていません。

+0

[Laravel 5.4内部エラー:デフォルト値の取得に失敗しました]の可能な重複(http://stackoverflow.com/questions/42816437/laravel-5-4-internal-error-to-default-value-to-default-value) – aynber

+2

あなたのユーザー名とパスワードフィールドのタイプはint(11)です。私は何か違うはずです。 –

+1

create宣言から 'array $ data'を取り出します。 – aynber

答えて

1

私はこれにRegisterController.phpcreate方法を変更する必要がありました:

/** 
* Create a new user instance after a valid registration. 
* 
* @return User 
*/ 
protected function create() 
{ 
    $this->validate 
    (
     request(), 
     [ 
      'username' => array(
       'required', 
       'max:80', 
       'min:4' 
      ), 
      'password'    => 'required|min:4', 
      'password_confirmation' => 'required|min:4', 
     ], 
     array (
      'required'    => 'Dies ist ein Pflichtfeld.' 
     ,'username.required'  => 'Projektname: Dies ist ein Pflichtfeld.' 
     ,'password.required'  => 'Passwort: Dies ist ein Pflichtfeld.' 
     ,'password_confirmation.required'  => 'Sie müssen das Passwort bestätigen!' 
     ) 
    ); 


    User::create([ 
     'username' => request('username'), 
     'password' => bcrypt(request('password')), 
    ]); 

    return view("main"); 
} 
関連する問題