这是我的代码:
//helpers.php
if (!function_exists('image_helper')) {
function image_helper($file = NULL, $path = NULL)
{
$image = app('image_helper');
if (!is_null($file) && is_null($path)) {
return $image->generateTmp($file);
}
return $image;
}
}
// ImageHelper.php
<?php
namespace App\Helpers;
use Illuminate\Http\File;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;
use Spatie\ImageOptimizer\OptimizerChainFactory;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class ImageHelper
{
private $fileName, $sizes;
function __construct()
{
$this->fileName = md5(time() . openssl_random_pseudo_bytes(16));
}
public function get($query, $path, $type)
{
$arr = [];
$sizes = getImageSizes($type);
$picture = $query->picture()->first();
if ($picture) {
foreach ($sizes as $key => $size) {
$url = filter_var($picture->file, FILTER_VALIDATE_URL) ?
$picture->file :
Storage::url($path . $key . '/' . $picture->file);
$arr = array_add($arr, $key, $url);
}
}
return $arr;
}
?>
我已经添加了我的composer.json:
"autoload": {
"classmap": [
"database/seeds",
"database/factories",
"app/Helpers/helpers.php"
],
"psr-4": {
"App\\": "app/"
},
"files": [
"app/Helpers/helpers.php"
]
},
运行此代码时:image_helper()->get($query, '/images');
我得到了ReflectionException (-1) Class image_helper does not exist
已经composer dump-autoload
,php artisan optimize
它仍然是相同的。
以前在Laravel 5.4上它运作得很好。
任何解决方案?
答案 0 :(得分:0)
问题出在你的辅助函数的这一行:
> library(data.table)
> df = data.frame(ID = c(1,1,1,2,2,3))
> df <- data.table(df)
> df[, occurrence := sequence(.N), by = c("ID")]
> df
ID occurrence
1: 1 1
2: 1 2
3: 1 3
4: 2 1
5: 2 2
6: 3 1
将其更改为:
$image = app('image_helper');
现在正在工作