mercredi 29 mai 2019

Call to a member function details() on null?

My code is:

$user = User::create([
   'email' => $request->email,
    'password' => Hash::make($request->password),
 ]);

$user_details = [
            'name' => $request->name,
            'address' => $request->address,
            'lastname' => $request->lastname,
            'secondname' => $request->secondname,
            'inn' => $request->inn,
            'fincode' => $request->fincode,
        ];

$user->details()->create($user_details);

Model User is:

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    public function details()
    {
        return $this->hasOne(UserDetails::class, 'user_id', 'id');
    }

}

UserDetails model is:

namespace App;

use Illuminate\Database\Eloquent\Model;

class UserDetails extends Model
{

    protected $table = 'enterprise';

    protected $fillable = ['name', 'lastname', 'secondname', 'address', 'inn', 'fincode'];
}



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2JKAbTU
via IFTTT

Aucun commentaire:

Enregistrer un commentaire