Я создаю приложение CMS, где пользователю, конечно, сначала необходимо зарегистрироваться или войти в систему.
Но у меня возникла проблема при отправке данных в базу данных.Это говорит 'Field 'remember_me' doesn't have a default value'
.
Я не могу найти, почему он ожидает значение по умолчанию, так как я отправляю данные Remember_me, то есть зарегистрированный => 1 и непроверенный => 0!Я использую Javascript для этого!
RegisterController.php
<?php
namespace App\Http\Controllers\Authentication;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
class RegisterController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
return view('auth.register');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create() {
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
$user = User::create($request->all());
return redirect('/');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id) {
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
//
}
}
register.blade.php
@extends('master')
@section('title')
Register - CMS APP
@endsection
@section('styles')
<link rel="stylesheet" href="{{ asset('css/auth.css') }}">
@endsection
@section('register')
<form class="form-signin" method="post" accept-charset="utf8" action="/register">
@csrf
<img class="mb-4" src="http://logo.kenh.net/logo/bootstrap-4.svg.png" alt="" width="72" height="72">
<h1 class="h3 mb-3 font-weight-normal">Please Register</h1>
<label for="inputFirstName" class="sr-only">First Name</label>
<input name="fname" type="string" id="inputFirstName" class="form-control" placeholder="First Name" required autofocus>
<label for="inputLastName" class="sr-only">Last Name</label>
<input name="lname" type="string" id="inputLastName" class="form-control" placeholder="Last Name" required autofocus>
<label for="inputEmail" class="sr-only">Email address</label>
<input name="email" type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input name="password" type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="checkbox mb-3">
<label>
<input name="remember_me" id="rememMe" type="checkbox" value="0"> Remember me
</label>
</div>
<button class="btn btn-lg btn-success btn-block" type="submit">Register</button>
<br>
<a href="/login" class="btn btn-primary">Login</a>
</form>
@endsection
<script>
window.onload = () => {
let rememberMe = document.getElementById('rememMe');
rememberMe.onclick = () => {
if(rememberMe.checked) {
rememberMe.value = 1;
}else {
rememberMe.value = 0;
}
}
};
</script>
Маршруты
Route::resource('register', 'Authentication\RegisterController')->only([
'index', 'store'
]);
Миграция:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->integer('role_id')->default(2);
$table->integer('is_active')->default(1);
$table->integer('remember_me');
$table->string('fname');
$table->string('lname');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
Пожалуйста, помогите мне исправить это!