0

Hello how can i upload multiple images to my table, for now i have this table

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

i want to store multiple images in "images" field, how could i do that ?

Fatih Akgun
  • 479
  • 1
  • 6
  • 18

1 Answers1

1

If you want to store the images data directly in a database column, it's not the best practice at all. Read this https://stackoverflow.com/a/6472268/830130

Differently if you want to do the right way in my opinion it's better to delete that string column you called "images" and create an images table, with a foreign key referencing the id on articles.

In Laravel the relation can be done using the Eloquent relationships.

In your case you can decide to have a one-to-many: https://laravel.com/docs/5.1/eloquent-relationships#one-to-many

or a many-to-many relationship: https://laravel.com/docs/5.1/eloquent-relationships#many-to-many

Community
  • 1
  • 1
Alessandro
  • 341
  • 1
  • 13