【发布时间】:2017-07-31 05:28:25
【问题描述】:
大家好,我的帖子表中有一行存在这个问题。
这是表格:
{{ 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() !!}
这是帖子迁移文件:
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');
}
这是我的控制器“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)
{
//
}
贴纸行属于我数据库上的帖子表,所以当我发布数据时会收到该错误消息。它昨天工作得很好,但是你移动了一些文件夹并且不小心删除了部分代码,所以我再次编写了它,但是有那个错误,以及这个社区帮助修复的另一个错误。
非常感谢
【问题讨论】:
-
您的表单中似乎不需要贴纸,请编辑迁移以创建此属性
->nullable() -
您能展示一下您的模型的结构吗?要查看您的模型中是否有您通过属性 fillable 发送数据
-
实际上我的 Posts 模型是空的,我还没有处理它。正如我所说,它昨天工作正常,但试图修复它我卡在那里
-
EddyTheDove 给出了答案,所以我要求您展示您的模型以确认您使用的是可填充属性。
-
@EdwardPalen 实际上这不是答案。问题是 class="form-control" 不要问我为什么,但据我记得昨天它正在与那个类一起工作,我决定删除那个类,瞧……现在运行顺利。