存储多个图像

时间:2016-06-07 01:02:27

标签: php mysql laravel

您好我怎样才能将多张图片上传到我的桌子,现在我有这张桌子

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');
    });

我想在"图像中存储多个图像"我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

如果要将图像数据直接存储在数据库列中,则根本不是最佳做法。阅读此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