Php 列已存在,但无法保存
列已存在,但无法保存Php 列已存在,但无法保存,php,sqlite,laravel-5,query-builder,laravel-5.8,Php,Sqlite,Laravel 5,Query Builder,Laravel 5.8,列已存在,但无法保存 index.blade.php <form action="{{route('work.store', ['id' => $param->id])}}" method="post"> @csrf <input type="hidden" name="project_id" value="{{$param->id}}"> public function store(Request $request,$id) { $work
index.blade.php
<form action="{{route('work.store', ['id' => $param->id])}}" method="post">
@csrf
<input type="hidden" name="project_id" value="{{$param->id}}">
public function store(Request $request,$id)
{
$work = new Work;
$work->fill($request->all())->save();
return redirect()->route('workindex', ['id' => $id]);
}
Schema::create('work', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('project_id');
$table->text('content');
$table->integer('user_id');
$table->time('work_time');
$table->string('input_person');
$table->timestamp('input_date');
$table->softDeletes();
$table->timestamps();
});
Route::post('/work/{id}', 'WorkController@store')->name('work.store');
创建工作表.php
<form action="{{route('work.store', ['id' => $param->id])}}" method="post">
@csrf
<input type="hidden" name="project_id" value="{{$param->id}}">
public function store(Request $request,$id)
{
$work = new Work;
$work->fill($request->all())->save();
return redirect()->route('workindex', ['id' => $id]);
}
Schema::create('work', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('project_id');
$table->text('content');
$table->integer('user_id');
$table->time('work_time');
$table->string('input_person');
$table->timestamp('input_date');
$table->softDeletes();
$table->timestamps();
});
Route::post('/work/{id}', 'WorkController@store')->name('work.store');
web.php
<form action="{{route('work.store', ['id' => $param->id])}}" method="post">
@csrf
<input type="hidden" name="project_id" value="{{$param->id}}">
public function store(Request $request,$id)
{
$work = new Work;
$work->fill($request->all())->save();
return redirect()->route('workindex', ['id' => $id]);
}
Schema::create('work', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('project_id');
$table->text('content');
$table->integer('user_id');
$table->time('work_time');
$table->string('input_person');
$table->timestamp('input_date');
$table->softDeletes();
$table->timestamps();
});
Route::post('/work/{id}', 'WorkController@store')->name('work.store');
存在但不存在
SQLSTATE[HY000]: General error: 1 table category has no column named project_id (SQL: insert into "category" ("project_id", "input_person", "input_date", "user_id", "estimated_work_time", "content", "updated_at", "created_at") values (4, 1, 2019-08-30 08:02:19, 1, 02:00, hoge, 2019-08-30 08:52:15, 2019-08-30 08:52:15))
看来你的桌名不对
SQLSTATE[HY000]: General error: 1 table category has no column named project_id (SQL: insert into "category"
插入到类别中,但您已创建表名工作。确保您的表具有项目id 或者确保在您的模型中它应该是可填充的
protected $fillable = [
'project_id'
];
为什么在隐藏中传递
project\u id
??您已经在发送操作参数。删除project\u id
input hidden。您是否已将project\u id字段添加到工作模型的$filleble属性中?@DilipHirapara,因为我只想将id传递给Route。@dparoli我忘了非常感谢
您也在实际传递它,对吗?错误是因为您使用了fill方法并在表单中传递了项目id,所以fill方法尝试在works表中查找项目id,但它不存在。这就是为什么会出现错误。现在如果您想重定向同一个页面,那么您可以使用return redirect()->back()->with('success',['your message,here'])代码>我忘记将其添加到fillable 非常感谢。