Forms\Components\FileUpload::make('image_upload')
->getUploadedFileUrlUsing(
//display uploaded image
function (Closure $get) {
if ($get('image_id')) {
$image = Image::find($get('image_id'));
return $image->storageLocation->host_name . '/' . $image->file_path;
}
}
)
->afterStateUpdated(
//upload the image
function (Closure $set, Closure $get, TemporaryUploadedFile $state, HandleImagesService $handleImagesService) {
$set(
'image_id',
$handleImagesService->handleImage(
null,
$state,
ModelsNamesWithImages::STATUS_IMAGE,
auth()->user()->role->id,
$get('force_upload') ?? false
)->id
);
}
),
ShowImage::make('image_show')
->afterStateHydrated(
//display the image
function (ShowImage $component, Closure $get) {
if ($get('image_id')) {
$image = Image::find($get('image_id'));
$component->state($image->storageLocation->host_name . '/' . $image->file_path);
}
})
->hidden(function (Page $livewire) {
return !$livewire instanceof Pages\EditStatusImage;
}),
Forms\Components\FileUpload::make('image_upload')
->getUploadedFileUrlUsing(
//display uploaded image
function (Closure $get) {
if ($get('image_id')) {
$image = Image::find($get('image_id'));
return $image->storageLocation->host_name . '/' . $image->file_path;
}
}
)
->afterStateUpdated(
//upload the image
function (Closure $set, Closure $get, TemporaryUploadedFile $state, HandleImagesService $handleImagesService) {
$set(
'image_id',
$handleImagesService->handleImage(
null,
$state,
ModelsNamesWithImages::STATUS_IMAGE,
auth()->user()->role->id,
$get('force_upload') ?? false
)->id
);
}
),
ShowImage::make('image_show')
->afterStateHydrated(
//display the image
function (ShowImage $component, Closure $get) {
if ($get('image_id')) {
$image = Image::find($get('image_id'));
$component->state($image->storageLocation->host_name . '/' . $image->file_path);
}
})
->hidden(function (Page $livewire) {
return !$livewire instanceof Pages\EditStatusImage;
}),