Ich versuche eine Register- und Login-Funktionalität zu implementieren. Es gibt bereits einige Standardmodelle und Auth-Controller in meinen Projekten, die ich verwende.Laravel 5.4 - Interner Fehler: Fehler beim Abrufen des Standardwerts
App/User.php
App/Http/Controllers/Auth/RegisterController.php
App/Http/Controllers/Auth/LoginController.php
Ich änderte nur name
-username
in all diesen Dateien.
Routes
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");
App/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',
];
}
App/HTTP/Controller/Auth/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');
}
}
Register anzeigen
<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>
Ich habe Migrationen nicht verwendet und erstellt die Tabelle users
von Hand.
Doch nach dem Absenden des Formulars erhalte ich:
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
Es ist nicht mather, wenn ich etwas eingeben, vor der Unterbreitung oder es leer senden, wird der Fehler erscheint immer.
Mögliche Duplikat [Laravel 5.4 Interner Fehler: Fehler beim Standardwert abzurufen] (http://stackoverflow.com/questions/42816437/laravel-5-4-internal-error-failed-to-require-the-default-Wert) – aynber
Nur etwas, was ich bemerke: Ihr Benutzername und Passwort-Feld haben einen Typ von Int (11). Sollte etwas anderes sein, hoffe ich. –
Nimm das Array $ data aus der create-Deklaration. – aynber