SQLSTATE[HY000]: General error: 1364 Feld "photo", keine Standard-Wert in laravel 5.5

Ich versuche, upload Fotos bei der Registrierung, aber ich bin immer dieser Fehler, ich suchte online und gründete mögliche Lösungen haben bei mir nicht funktioniert. Ich bin mit sentinel-Paket für die erweiterte Authentifizierung. Bitte mir jemand helfen .
Hier meine controller-

 public function postRegister(Request $request){
    $request->validate([
        'first_name' => 'required|max:255',
        'last_name' => 'required|max:255',
        'user_name' => 'unique:users|max:255',
        'email' => 'required|unique:users|email|max:255',
        'password' => 'required|min:6|confirmed',
        'phone' => 'required|numeric',
    ]);
    //upload image
    if ($file = $request->file('photo')) {
        $fileName = $file->getClientOriginalName();
        $extension = $file->getClientOriginalExtension() ?: 'png';
        $folderName = '/uploads/users/';
        $destinationPath = public_path() . $folderName;
        $safeName = str_random(10) . '.' . $extension;
        $file->move($destinationPath, $safeName);
        $request['photo'] = $safeName;
    }

    //$user = Sentinel::registerAndActivate($request->all());
    $user = Sentinel::registerAndActivate($request->all());
    //dd($user);
    //$activation = Activation::create($user);

    $role = Sentinel::findRoleBySlug('member');

    $role->users()->attach($user);
    //$this->sendEmail($user, $activation->code);
    //return redirect('/login');
    return ('You have seccsessfully registered. Now login to start');
}

Form und input-(mit enctype="multipart/form-data" top of form)

 <div class="row">
    <div class="col-md-6">
      <div class="sponsor-row">
        <label for="sponsor_input"><i class="fa fa-tags"></i></label>
        <input type="text" name="sponsor" id="sponsor_input" class="sponsor-input" placeholder="Sponsor"></input>
      </div>
    </div>
    <div class="col-md-6">
      <div class="photo-row">
        <label for="photo_input"></label>
        <input type="file" name="photo" id="photo" class="photo-input"></input>
      </div>
    </div>
  </div>
</div>

Meine Benutzer-Modell:

<?php

namespace-App;

verwenden Sie Beleuchten\Benachrichtigungen\Meldepflichtigen;
verwenden Sie Beleuchten\Foundation\Auth\User wie Authenticatable;

class User extends Authenticatable
{
verwenden Meldepflichtigen;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'first_name', 'last_name', 'user_name','email', 'password', 'phone', 'location', 'sponsor', 'photo',
];

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

}

Meine Migration Code:

Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('first_name')->nullable();
        $table->string('last_name')->nullable();
        $table->string('user_name');
        $table->string('email');
        $table->string('password');
        $table->string('phone');
        $table->string('location');
        $table->string('sponsor');
        $table->binary('photo')->nullable();
        $table->text('permissions')->nullable();
        $table->timestamp('last_login')->nullable();
        $table->timestamps();

        $table->engine = 'InnoDB';
        $table->unique('email');
    });
  • Datenbank-Tabelle-Spalte Foto müssen einen Standardwert, wie etwa null
  • nur ein default-Wert für Ihre photo Spalte in Ihrer Tabelle in der Regel null
  • Posten Sie Ihre Sentinel-Model & Migration Code..
  • Hier ist meine User-Model - protected $fillable = [ 'first_name', 'last_name', 'Benutzername','email', 'password', 'Telefon', 'location', 'sponsor', 'Foto', ];
  • Und hier ist migration - Schema::create('users', function (Blueprint $Tabelle) { $table-> - Schritten('id'); $Tabelle->string('first_name')->nullable(); $Tabelle->string('last_name')->nullable(); $Tabelle->string('user_name'); $Tabelle->string('email'); $table->string ("Passwort"); $Tabelle->string('Telefon'); $Tabelle->string('location'); $Tabelle->string('sponsor'); $Tabelle->binary('Foto')->nullable();
  • $table->text ("Berechtigungen")->nullable(); $Tabelle->timestamp('last_login')->nullable(); $Tabelle->der Zeitstempel(); $Tabelle->engine = 'InnoDB'; $Tabelle->unique('E-Mail'); });

InformationsquelleAutor Rashed Hasan | 2017-09-20
Schreibe einen Kommentar