
前提
ここに質問の内容を詳しく書いてください。
投稿をクリックすると、エラーが出る。
実現したいこと
フォームにタイトル・コメントを入力すると投稿ができ、データベースに追加される
発生している問題・エラーメッセージ
SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value insert into `books` (`title`, `comments`, `updated_at`, `created_at`) values (a, a, 2022-10-11 06:08:42, 2022-10-11 06:08:42)
該当のソースコード
book/create.blade.php
@extends('front.layouts.master') @section('title','トップページ | Laravel') @include('front.partials.header') @section('content') <h1>著者登録ページです。</h1> @endsection @section('list') <h2 class="author_register">著者登録</h2> {!! Form::open(['route'=>'book.store']) !!} <div class="author_form"> <span class="author_title">著書名</span>{!! Form::text('title',null, ['placeholder' => 'タイトルを入力してください'],) !!} </div> <div class="author_form"> <span class="author_name">著者名</span>{!! Form::select('author_name', $books->pluck('name')) !!} </div> <div class="author_form"> <span class="author_comments">コメント</span>{!! Form::textarea('comments',null, ['placeholder' => '本文を入力してください', 'cols' => '20', 'rows' =>'5']) !!} </div> <div class="author_submit"> {!! Form::submit('投稿') !!} <a href="{{ route('home.books') }}">{!! Form::button('キャンセル') !!}</a> </div> {!! Form::close() !!} @endsection @include('front.partials.footer')
Bookcontroller
public function store(Request $request) { $books = new Book; $books->title=$request->input('title'); $books->comments=$request->input('comments'); $books->save(); return redirect('front.book.index'); }
試したこと
valueがないエラーだったのでvalueを入れても、結果は変わりませんでした。
補足情報(FW/ツールのバージョンなど)
laravel8
使用:laravelcollective/html

m.ts10806が「BooksテーブルのnameカラムがNOT NULLであること」の証明をできるように、質問を修正せよ。
