laravel - 不更新数据库也不在 laravel 中抛出错误
问题描述
更新用户时遇到问题。当我在单击保存按钮后尝试更新用户时,它会将我重定向到同一页面并且不会向我抛出任何错误,但也不会更新数据库中的任何内容。下面是我的代码。我不知道这里发生了什么。帮我 :)
控制器
public function update(ReportRequest $request, $id)
{
$report = Report::findOrFail($id);
$input = $request->all();
if ($file = $request->file('photo_id')) {
$name = time() . $file->getClientOriginalName();
$file->move('images', $name);
$photo = Photo::create(['file' => $name]);
$input['photo_id'] = $photo->id;
}
$report->update($input);
return redirect()->back();
}
路线
Route::resource('admin/reports', 'ReportController', ['names'=>[
'index'=>'admin.reports.index',
'create'=>'admin.reports.create',
'edit'=>'admin.reports.edit',
]]);
楷模
class Report extends Model
{
protected $fillable = [
'student_id',
'student_name',
'class_id',
'subject',
'teacher_name',
'report_categories_id',
'total_marks',
'obtained_marks',
'percentage',
'position',
'photo_id',
];
public function photo() {
return $this->belongsTo('App\Photo');
}
public function studentsClass() {
return $this->belongsTo('App\StudentsClass', 'class_id');
}
public function student() {
return $this->belongsToMany('App\Student');
}
}
解决方案
确保在and模型中有$fillable
属性,否则and方法将无法按预期工作。Photo
Report
create()
update()
推荐阅读
- pandas - 切断熊猫数据框中阈值的值
- r - 在 rmarkdown 的 hist 函数中使用 add = TRUE 时出错
- ios - WebCore WebCore::GraphicsContext3D::reshape(int, int)
- android - Gradle 构建失败:找不到方法 org.gradle.tooling.model.gradle.GradleBuild.getIncludedBuilds
- hive - Hive INSERT INTO vs UNION ALL 性能
- python - Slack API - rtm_connect 错误
- postman - 为什么 Insomnia 开始认不出西里尔字母?
- ionic-framework - Ionic 3 组合标签页和侧边菜单不起作用
- python - 在 Python 中比较两个 Microsoft Excel 文件
- laravel - Laravel 5.6 模型关系和数组