dpt62283 2017-03-10 01:46
浏览 49

SQLSTATE [23000]:完整性约束违规:1048列'贴'不能为null Laravel

Hi everyone im having this issue with a row on my posts table.

This is the form:

                    {{ Form::label('title', ' Título', array('class' => 'fa fa-pencil')) }}

                    {{ Form::text('title', null, array('class' => 'form-control', 'required' => '', 'maxlength' => '255', 'placeholder' => 'Ingresar Título')) }}

                    {{ Form::label('body', ' Contenido', array('class' => 'fa fa-pencil-square-o')) }}

                    {{ Form::textarea('body', null, ['class' => 'form-control', 'required' => '', 'placeholder' => 'Redactar Contenido']) }}

                    {{ Form::submit('Publicar', array('class' => 'btn btn-info')) }}


                </div>
            </div> <!-- col-md-8 end -->


            <div class="col-md-4">
            <div class="input-group">
                <h3 class="text-center">Categoría e imágen</h3>
                <hr>


                     <br> <hr>

                    {{ Form::label('stickers', ' Etiqueta', array('class' => 'fa fa-tags')) }}
                    {{ Form::text('stickers', '', array('class' => 'form-control', 'maxlength' => '20', 'placegolder' => 'Ingresar Etiqueta')) }}

                    <br> <hr>
                    {{ Form::label('postimg', ' Seleccionar Imagen', array('class' => 'fa fa-picture-o')) }}
                    {{ Form::file('postimg') }}

                {!! Form::close() !!}

This is the Posts Migration file:

public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->increments('id');
        $table->string('title');
        $table->string('stickers');
        $table->text('body');
        $table->string('postimg');
        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('posts');
}

And this is part of my Controller "PostsController" :

public function create()
{
    return view('posts.create');
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    // validate the data
    $this->validate($request, array(
        'title' => 'required|max:255',
        'body' => 'required',
        ));

    // store in database
    $post = new Post;

    $post->title = $request->title;
    $post->body = $request->body;
    $post->stickers = $request->stickers;
    $post->postimg = $request->postimg;

    $post->save();

    Session::flash('success', 'La publicación se ha creado correctamente');

    // redirect to another page
    return redirect()->route('posts.show', $post->id);
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function show($id)
{
    $post = Post::find($id);
    return view('posts.show')->withPost($post);
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
    //
}

The sticker row belongs to posts table on my database, so when i post the data get that error message. It was working perfectly yesterday but y moved some folders and accidentally i delete part of the code so i wrote it again but with that bug, and another one that this community helped to fix.

Thanks a lot

  • 写回答

2条回答 默认 最新

  • douman6679 2017-03-10 01:57
    关注

    In your model, add 'stickers' to the fillable array

    protected $fillable = ['stickers']; //and any other mass asignable field. 
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了