I am doing registration on my new project on Laravel and getting an error SQLSTATE[HY000]: General error: 1364 Field 'login' doesn't have a default value (SQL: insert into users
() values ()) Here is my code. View:
@extends('app')
@section('content')
<h1>Регистрация</h1>
<form action="/user/" method="post">
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" id="email" name="email">
</div>
<div class="form-group">
<label for="login">Login</label>
<input type="text" class="form-control" name="login">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password">
</div>
<div class="form-group">
<label for="password-repeat">Repeat password</label>
<input type="password" class="form-control" id="password-repeat" name="password-repeat">
</div>
<button type="submit" class="btn btn-default">Регистрация</button>
</form>
@stop
Controller:
public function create()
{
$userConstuctor['login'] = Request::input('login');
$userConstuctor['password'] = Request::input('password');
$user = new User($userConstuctor);
$user->setUser(Request::all());
$user->save();
}
Model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Session;
class User extends Model
{
const ADMIN = 1;
const MANAGER = 2;
const USER = 3;
public $login;
public $password;
private $email;
private $firstName;
private $secondName;
private $lastName;
private $avatar;
private $userOptions = [];
private $createdDate;
private $rememberToken;
private $active;
private $groupId;
public $timestamps = false;
protected $fillable = ['login', 'password', 'email', 'created_date', 'remember_token', 'active', 'group_id'];
protected $table = 'users';
public function __construct($userConstuctor)
{
$this->setLogin($userConstuctor['login']);
$this->setPassword($userConstuctor['password']);
}
public function setUser($user)
{
$this->setEmail($user['email']);
$this->setCreatedDate();
$this->setRememberToken($user['_token']);
$this->setActive();
$this->setGroupId();
}
private function setLogin($login)
{
$this->login = $login;
}
private function setPassword($password)
{
$this->password = md5($password);
}
private function setEmail($email)
{
$this->email = $email;
}
private function setCreatedDate()
{
$this->createdDate = date('Y-m-d H:i:s');
}
private function setRememberToken($token)
{
$this->rememberToken = $token;
}
private function setActive()
{
$this->active = false;
}
private function setGroupId()
{
$this->groupId = self::USER;
}
}
Table Schema:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('login')->unique();
$table->string('email')->unique();
$table->string('password');
$table->string('first_name')->nullable();
$table->string('second_name')->nullable();
$table->string('last_name')->nullable();
$table->string('avatar', 250)->nullable();
$table->longText('user_options')->nullable();
$table->timestamp('created_date');
$table->boolean('active');
$table->rememberToken('token');
$table->integer('group_id');
});
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2yxv54A
via IFTTT
Aucun commentaire:
Enregistrer un commentaire