为什么值没有保存到数据库中?

时间:2016-06-19 21:56:44

标签: php database laravel

为什么我的值没有进入数据库?

如果需要更多代码,请告诉我。

警告:

Connection.php第713行中的QueryException: SQLSTATE [23000]:完整性约束违规:1048列'name'不能为空(SQL:插入bookmarks nameseasonepisode,{{1} },updated_at)值(,, 2016-06-19 21:44:05,2016-06-19 21:44:05))

控制器:

created_at

HTML页面:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Bookmark;
use App\Http\Requests;

class BookmarkController extends Controller
{
    public function __construct() {
        $this->middleware('auth');
    }

    public function index() {
        return view('bookmarks.bookmarks');
    }

    public function save(Request $request) {
        $bookmark = new Bookmark;
        $bookmark->name = $request->name;
        $bookmark->season = $request->season;
        $bookmark->episode = $request->episode;

        $bookmark->save();

        return redirect('bookmarks');
    }

    public function add() {
        return view('bookmarks.add');
    }
}

1 个答案:

答案 0 :(得分:2)

这就是HTML的样子:

@extends('layouts.app')

@section('content')

<div class="container">
    <h1 class="text-center">Add Bookmark</h1>

    <form method="post" action="{{ url('/bookmarks') }}">
        {{ csrf_field() }}
        <div class="form-group">
            <label for="name">Name:</label>
            <input type="text" class="form-control" id="name" name="name" placeholder="Name">
        </div>
        <div class="form-group">
            <label for="season">Season:</label>
            <input type="text" class="form-control" id="season" name="season" placeholder="Season">
        </div>
        <div class="form-group">
            <label for="episode">Episode:</label>
            <input type="text" class="form-control" id="episode" name="episode" placeholder="Episode">
        </div>
        <button type="submit" class="btn btn-primary">Add Booenter code herekmark</button>
    </form>
</div>

@endsection

您忘记将name属性添加到输入元素