php - Laravel 问题请求图像数据也将其存储在其他地方
问题描述
我遇到了一个我现在无法自行解决的问题 2 天。
我正在使用 laravel 并创建一个帖子:
在那里,我正在创建帖子,并且还想在浏览器的视图层中选择要选择的照片。它应该被选中并存储在我的帖子数据库中。您会看到我的 PostController 的代码。
public function store(Request $request)
{
// Validate posted form data
$validated = $request->validate([
'title' => 'required|string|unique:posts|min:5|max:100',
'content' => 'required|string|min:5|max:2000',
'image' => 'image|mimes:jpeg,png,jpg,gif,svg|max:5000',
]);
$data['title'] = $request->title;
$data['content'] = $request->content;
$data['image_gallery'] = $request->path;
// Create and save post with validated data
$post = Post::create($validated);
// Redirect the user to the created post with a success notification
return redirect(route('posts.index'))->with('notification', 'Post erstellt');
}
还有我的帖子创建视图的代码:
<label class="label">Beitragsbild: </label>
<div class="field">
<select id="id_select2_example" style="width: 220px;">
@foreach($images as $image)
<option data-img_src="/image/{{ "$image->id" }}">{{ $image->title }}</option>
@endforeach
</select>
</div>
这是来自浏览器的错误,但我无法利用它。
SQLSTATE[HY000]:一般错误:1364 字段“image_gallery_id”没有默认值(SQL:插入
posts
(title
、、、、content
) 值updated_at
created_at
如果我能得到一些提示/进一步的帮助,我将不胜感激!
解决方案
推荐阅读
- c# - 如何将字符串与元组匹配
- python - 删除二维数组python中的空单元格
- php - Vue模块未编译
- c++ - 将另一个函数作为参数的函数,“无匹配函数错误”C++
- visual-studio-code - VSCode/Cmake Tools:添加外部头库
- maven - Azure DevOps 手动将外部库发布到 Azure Artifacts?
- javascript - 用于将子级附加到函数调用者/调用者的 ES6 Javascript
- javascript - 表单中超过 1 个文件输入功能无效
- sql - 想要组合三个单独的追加查询并将最终结果显示在单行上
- node.js - 无法访问 docker 内的 Web 应用程序