2017-06-28 1 views
0

Ich habe diesen Fehler bei der Registrierung der Benutzer mit Bild-Upload-Funktion erhalten. Ich habe alle Details richtig angegeben, aber nicht herausfinden, was passiert. Bitte schauen Sie sich das an .... Danke im Voraus. Hier enter image description here(3/3) QueryException SQLSTATE [HY000]: Allgemeiner Fehler: 1364 Feld 'userimage' hat keinen Standardwert

ist die Steuerung:

<?php 
 

 
namespace App\Http\Controllers\Auth; 
 

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

 

 
use Illuminate\Support\Facades\Storage; 
 

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

 
    /** 
 
    * 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, [ 
 
      'name' => 'required|string|max:255', 
 
      'email' => 'required|string|email|max:255|unique:users', 
 
      'password' => 'required|string|min:6|confirmed', 
 
      'userimage' => 'required|image' 
 
     ]); 
 
    } 
 

 
    /** 
 
    * Create a new user instance after a valid registration. 
 
    * 
 
    * @param array $data 
 
    * @return User 
 
    */ 
 
    protected function create(array $data) 
 
    { 
 
     $path = Storage::putFile('userimages',$data['userimage']); 
 
     return User::create([ 
 
      'name' => $data['name'], 
 
      'email' => $data['email'], 
 
      'password' => bcrypt($data['password']), 
 
      'userimage' => $path, 
 
     ]); 
 
    } 
 
}

Modell ist ::

<?php 
 

 
namespace App; 
 

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

 
class User extends Authenticatable 
 
{ 
 
    use Notifiable; 
 

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

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

 
    public function todo() 
 
    { 
 
     return $this->hasMany('App\Todo'); 
 
    } 
 
}

und in der filesystems.php

<?php 
 

 
return [ 
 

 
    /* 
 
    |-------------------------------------------------------------------------- 
 
    | Default Filesystem Disk 
 
    |-------------------------------------------------------------------------- 
 
    | 
 
    | Here you may specify the default filesystem disk that should be used 
 
    | by the framework. The "local" disk, as well as a variety of cloud 
 
    | based disks are available to your application. Just store away! 
 
    | 
 
    */ 
 

 
    'default' => env('FILESYSTEM_DRIVER', 'public'), 
 

 
    /* 
 
    |-------------------------------------------------------------------------- 
 
    | Default Cloud Filesystem Disk 
 
    |-------------------------------------------------------------------------- 
 
    | 
 
    | Many applications store files both locally and in the cloud. For this 
 
    | reason, you may specify a default "cloud" driver here. This driver 
 
    | will be bound as the Cloud disk implementation in the container. 
 
    | 
 
    */ 
 

 
    'cloud' => env('FILESYSTEM_CLOUD', 's3'), 
 

 
    /* 
 
    |-------------------------------------------------------------------------- 
 
    | Filesystem Disks 
 
    |-------------------------------------------------------------------------- 
 
    | 
 
    | Here you may configure as many filesystem "disks" as you wish, and you 
 
    | may even configure multiple disks of the same driver. Defaults have 
 
    | been setup for each driver as an example of the required options. 
 
    | 
 
    | Supported Drivers: "local", "ftp", "s3", "rackspace" 
 
    | 
 
    */ 
 

 
    'disks' => [ 
 

 
     'local' => [ 
 
      'driver' => 'local', 
 
      'root' => storage_path('app'), 
 
     ], 
 

 
     'public' => [ 
 
      'driver' => 'local', 
 
      'root' => storage_path('app/public'), 
 
      'url' => env('APP_URL').'/storage', 
 
      'visibility' => 'public', 
 
     ], 
 

 
     's3' => [ 
 
      'driver' => 's3', 
 
      'key' => env('AWS_KEY'), 
 
      'secret' => env('AWS_SECRET'), 
 
      'region' => env('AWS_REGION'), 
 
      'bucket' => env('AWS_BUCKET'), 
 
     ], 
 

 
    ], 
 

 
];

+0

make '' userimage' nullable' in Ihrer Migrationsdatei –

+1

Sie haben ein Pflichtfeld für Bild in der Validierung und auch Sie vorbei Benutzer Bild in dem erstellen Funktion, wenn Sie also kein Bild hochladen wird es werfen und Fehler, – Exprator

Antwort

3

-Code für User Modell-Datei: Hier können Sie user_image und in Ihrem Controller userimage gegeben haben, so dass der Wert von user_image ist null. Deshalb bekommst du Fehler. Ändern Sie Variablennamen von der Steuerung zu user_image und machen nullable in Datenbank

protected $fillable = [ 
    'name', 'email', 'password', 'user_image', 
]; 
+0

Dank Bruder :) dumme Fehler .. –

Verwandte Themen