doulan8846 2018-08-04 18:50
浏览 58
已采纳

如果我想要一张附有其他图像的图像,我是否需要多个数据库表?

Users will be able to upload 1 or as many images as they want using multiple image input.

Images table
Columns: id, name, description, user_id, file_name

The home will display the images but not display the accompanying images, they will be displayed on the specific image page. If the user uploads 1 image, there won't be accompanying images.

Home page would be something like this:

@foreach($images as $image)
    <a href='{{url("image/".$image->id)}}'>
        <img src='{{url("storage/uploads/images/thumbnails/".$image->file_name)}}' alt='Random image'/>
    </a>
@endforeach

For simplicity, in the case of multiple images upload the first image in the array will be the main image that will be displayed on home.blade.php and will be saved in file_name column in images table.

On the specific image page, if the image does not have any accompanying images it should only have 1 image like this:

<img src='{{url("storage/uploads/images/specificImages/".$image->file_name)}}' alt='Random image' />

and if it has accompanying images it should display the main image and then the accompanying images.

Now my question is whether I should create a second table and model for the accompanying images or should I add a field in images table like collection that will contain an unique value that will be shared between images from same collection?

  • 写回答

1条回答 默认 最新

  • dqby43944 2018-08-04 18:58
    关注

    Now my question is whether I should create a second table and model for the accompanying images or

    It should be perfectly sufficient to add new column to existing table named i.e. parent_id and set its value for all accompanying images to id of the image they accompany (1st one from your set). And for that parent image's record, you keep that field set i.e. to NULL to indicate this one has no parent.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?