Wie bekomme ich user_id
= null?Laravel Formular nullable user_id
Logic:
Ich habe Zeugnis, wo ich manuell Benutzerinformationen füllen oder einfach nur eine meiner bestehenden Benutzer wählen, das Problem ist, wenn ich versuche, Testimonial mit manuellen Benutzern zu speichern erhalte ich The user id must be a number.
Fehler.
hier ist mein Speicher-Methode:
$this->validate($request, array(
// rest of code
'user_id' => 'nullable|numeric',
));
$testimonial = new Testimonial;
// rest of code
$testimonial->user_id = $request->input('user_id');
// rest of code
Das ist meine Form ist:
{{ Form::label('user_id', 'User') }}
<select class="form-control" name="user_id">
<option>Select User</option>
@foreach($users as $user)
<option value="{{ $user->id }}">{{ $user->username }}</option>
@endforeach
</select>
Hier mein Schema ist:
Schema::create('testimonials', function (Blueprint $table) {
// rest of code
$table->integer('user_id')->unsigned()->nullable();
});
Schema::table('testimonials', function (Blueprint $table) {
// rest of code
$table->foreign('user_id')->references('id')->on('users');
});
Wie kann ich auf das akzeptieren null übergeben Feld?
Stellen Sie sicher, dass Ihr 'select' der gleiche Teil des Formulars ist, das Sie senden. – usrNotFound