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.

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

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分