laravel-admin 实现在指定的相册下添加照片

(编辑:jimmy 日期: 2025/11/6 浏览:2)

相册与照片是一对多的关系,有以下需求:

1、点开一条相册数据看到相册的照片列表

2、为相册添加照片时,表单中要看到相册的基本信息

以下是实现步骤:

第一步:构建带参数路由:

$router->resource('manage/{albumid}/photo',Manage\PhotoController::class);

第二步:处理操作对应的函数:

(1)列表查看

public function index($albumid)
 {
 return Admin::content(function (Content $content)use($albumid) {

  $content->header('header');
  $content->description('description');

  $content->body($this->grid($albumid));
 });
 }

 protected function grid($albumid)
 {
 return Admin::grid(Photos::class, function (Grid $grid)use($albumid) {

  $grid->model()->where('album_id',$albumid);
  ......
  }
 }

(2)创建照片,并在创建表单上显示所属相册的基本属性

protected function form()
 {
 return Admin::form(Photos::class, function (Form $form){
  $paramters = request()->route()->parameters();

  $artworkid = isset($paramters['albumid'])"htmlcode">
 //重写update,多接收一个参数
 public function update($album,$id)
 {
 return $this->form()->update($id);
 }


(4)删除照片

 //重写destroy,多接收一个参数
 public function destroy($albumid,$id)
 {
 if ($this->form()->destroy($id)) {
  return response()->json([
  'status' => true,
  'message' => trans('delete_succeeded'),
  ]);
 } else {
  return response()->json([
  'status' => false,
  'message' => trans('delete_failed'),
  ]);
 }
 }

以上这篇laravel-admin 实现在指定的相册下添加照片就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。