I have different folders in my aws s3 for different types of images, so I have multiple s3 disks in my filesystems.php. I need to be able to dynamically insert the correct driver depending on where the image was stored. In the photo model, there is a column called folder_path, which stores the correct driver ('s3-images' or 's3-crusades') depending on what was used during the original upload.
filesystems.php
's3-images' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => 'cfanweb.images',
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
'visibility' => 'public'
],
's3-crusades' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => 'cfanweb.crusades',
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
'visibility' => 'public'
],
in my photo.php I would like to do something like ->disk(function () { do something } but it seems like you can't use a function inside the Image::make ->disk.
I get "message: "Illegal offset type", exception: "TypeError",…"
I would like to do something similar to what I did to retrieve the thumbnail:
Image::make('Image')
->disk(function ($model) {
dd($model->folder_path);
})
or
Image::make('Image')
->disk(function ($value) {
if($this->resource->folder_path) {
$disk = $this->resource->folder_path;
return $disk;
} else {
$disk = 's3-images';
return $disk;
}
})
->thumbnail(function ($value, $disk, $model) {
if ($value) {
$url = Storage::disk($this->folder_paths)->url($value);
return $url ?? null;
} else {
return null;
}
})
->preview(function ($value, $disk) {
if ($value) {
$url = Storage::disk($disk)->url($value);
return $url ?? null;
} else {
return null;
}
})
->store(new PhotoUpload)
->creationRules('required')
->readonly(function ($request) {
return $request->isUpdateOrUpdateAttachedRequest();
}),
I even tried setting the variable before the return in the function fields (however bad it looked), but when you try to use the variable in the ->disk($variable) it doesn't work.
Anybody have any ideas