如何使用laravel中的规范化更新多个图像

时间:2017-07-12 11:10:02

标签: php mysql laravel-5.4

我使用Laravel框架上传了多个图像,我想更新

images.How我能做到。

create table if not exists `teacher` (
  `id` int(10) unsigned not null auto_increment,
  `name` varchar(50) not null,
  primary key (`id`)
) engine=innodb auto_increment=3 default charset=utf8;

create table if not exists `teacher_document` (
  `id` int(10) unsigned not null auto_increment,
  `teacher_id` int(10) unsigned not null,
  `image` varchar(50) not null,
  primary key (`id`),
  key `org_id` (`teacher_id`),
  constraint `fk_org` foreign key (`teacher_id`) references `organisations` (`id`) on delete cascade on update cascade
) engine=innodb auto_increment=6 default charset=utf8;

在我想要更新一些图像之后成功插入数据。我不知道如何获取更新的图像ID然后更新特定图像。

if($request->hasFile('documentImageData')) {


     for($i=0;$i < count($data['documentImageData']);$i++) {

       $file = $data['documentImageData'][$i];
       $document = str_replace([' ', ':'], '-',date('Y-m-d').'-'.date("h-i-s-a")).'-' .$file->getClientoriginalName();
       $path=base_path().'/media/teacherDocument/';
       $file->move($path,$document);
     }
     }else{
      echo "";
    }

图像转到文件夹但我也想将记录更新到teacher_document表中如何获取特定的更新图像ID以便我可以使用更新查询 对于teacher_update表。

1 个答案:

答案 0 :(得分:0)

如果您上传文件或图片,请使用:

$path = $request->photo->store('images');

之后用$ path更新teacher_document