php - laravel 使用 find 时出现此错误:调用未定义的方法 Intervention\Image\ImageManager::find()
问题描述
我正在通过刀片中的帖子关系访问图像。我想通过已有的循环删除特定图像。而且我能够将特定图像获取到函数destroyImg。但我未能在destroyImg中删除它。
当我首先尝试找到它时,我收到了这个错误:
Call to undefined method Intervention\Image\ImageManager::find()
当我按 id 杀死和转储图像时,我可以看到特定的图像。例如:
{
"id": 79,
"post_id": 31,
"image": "1596537701-116796500_331884521301081_8587878113120337546_n.jpg",
"created_at": "2020-08-04T10:41:41.000000Z",
"updated_at": "2020-08-04T10:41:41.000000Z"
}
刀片文件
@foreach($posts as $post)
@for($i=0; $i< count($image = $post->images()->get()); $i++)
//loop has some own operations here
<form action="/img/delete/{{$image[$i] }}" enctype="multipart/form-data" method="POST">
</form>
@endforeach
后控制器
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Intervention\Image\Facades\Image;
use Carbon\Carbon;
use App\User;
use App\Post;
use Illuminate\Http\Request;
public function destroyImg($id)
{
dd($id);
$try = Image::find($id);
//$id->delete();
$user = Auth::guard('web')->id();
($user);
return redirect()->route('home',['user'=>$user]);
}
解决方案
随着表格从更改{{$image[$i]['id'] }}
为我设法通过在destroyImg函数{{$image[$i]->id }}
中传递模型来使用图像模型查找。
注:图片模型为images
后控制器
use Intervention\Image\Facades\Image;
use App\images;
public function destroyImg(images $images, $id)
{
$try = images::find($id);
$try->delete();
$user = Auth::guard('web')->id();
return redirect()->route('home',['user'=>$user]);
}
推荐阅读
- vue.js - 带有 VueJS 的客户端 OAuth2 应用程序 - 需要服务器组件吗?
- javascript - javascript+browser 复制到剪贴板失败,数据超过 ~150k 使用 document.execCommand('copy')
- unicode - Common Lisp 中 unicode 字符的语法(如果有)是什么?
- angularjs - Angularjs 将 1.3 迁移到 1.6 和 $http.get()
- botframework - 如何为 Bot Framework (Skype) 设置 webhook 回调 url?
- c++ - 使用 Websocket++ 绑定到特定的 IP 地址
- r - 编写与操作系统无关的文件路径
- authentication - node-red:多用户仪表板 + node-red-contrib-users
- php - 无法用php将数据插入mysql
- vba - 复制的文本以布尔值返回