您好,我如何将多个图像上传到我的表格,现在我有这个表格
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->integer('category_id')->unsigned();
$table->string('title', 70);
$table->string('slug', 100)->unique();
$table->string('images');
$table->text('content');
$table->softDeletes();
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
我想在“图像”字段中存储多个图像,我该怎么做?
最佳答案
如果您想将图像数据直接存储在数据库列中,这根本不是最佳实践。阅读此https://stackoverflow.com/a/6472268/830130
不同的是,如果您想以正确的方式进行操作,我认为最好删除名为“images”的字符串列并创建一个图像表,并使用引用文章上的 id 的外键。
在 Laravel 中,可以使用 Eloquent 关系来完成关系。
根据您的情况,您可以决定进行一对多: https://laravel.com/docs/5.1/eloquent-relationships#one-to-many
或多对多关系:https://laravel.com/docs/5.1/eloquent-relationships#many-to-many
关于php - 存储多张图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37668977/