【发布时间】:2022-01-27 16:20:52
【问题描述】:
我想迁移 MySQL 数据库中的文件,但我似乎无法在 Laravel 中正确获取文件的数据类型。如果可以请帮忙
我已阅读Link,但它并没有解决我的问题。
我是初学者,如果您发现这个问题不成熟,请耐心等待(我们都必须从某个地方开始记住)
我的迁移摘录如下:
public function up()
{
Schema::create('student', function (Blueprint $table) {
$table->id();
**$table->string('file');**
$table->string('semester');
$table->timestamps();
});
}
这也是我的请求文件
{
return [
'file' => 'required',
'semester' => 'required|string|max:255',
];
}
这也是我的控制器文件
public function store(CEStoreRequest $request)
{
CE::create([
'file' => $request->file('file'),
'semester' => $request->semester,
]);
return redirect()->route('home.index')->with('success', 'Project created successfully');
}
【问题讨论】:
-
你查看过关于 Laravel 文件存储的文档吗? laravel.com/docs/8.x/filesystem。通常,您上传文件某处,例如 Laravel 的
storage/framework中的本地文件夹,或 Amazon S3 等外部服务,然后只需将文件的信息存储在数据库中,通常是文件名的字符串/存储位置,以及一些元数据,如文件类型、文件大小等。 -
我不确定,但也许字符串的大小对于文件来说太小了,也许你需要更大的?你可以在这里选择数据类型laravel.com/docs/8.x/migrations#available-column-types
-
让我按照@TimLewis 的建议检查文档
-
@VasoGamdelidze 感谢您的评论。