Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

akvaskov's avatar

Add image in Laravel/Filament form

0

I'm trying to build a wizard form in Filament. It has 2 steps:

First, an user need to specify some product number. After that script gets some info including image url from other site by api. I want a respective image to be displayed on this step. As a result the user should confirm that it's a product he needs. And now I don't understand how to display the image in this form. It's not a file uploader. It's just an image.

As I understand, it can be done via ViewField. But don't understand how to specify that it should be some Image component and how to pass an url there in afterValidation on the first step. Please, help.

public function getSteps(): array
    {
        return [
            Step::make('Product ID')
                ->description('Write a product id you want')
                ->schema([
                    TextInput::make('product_id')
                        ->required()
                        ->reactive()
                ])
                ->afterValidation(function(Get $get, Set $set){
                    $id = $get('product_id');
                    $product_image_url = Product::get_image_url($id);
                    $set('product_image', $product_image_url);
                }),
            Step::make('Confirmation')
                ->description('Check a product one more time and confirm you want it')
                ->schema([
                    ViewField::make('product_image')
                       ...............
                       ...............
                ]),
0 likes
1 reply
aurawindsurfing's avatar

ViewField has a property ->view('your_view.blade.php') and here you use just standard blade to tell it what to display

Please or to participate in this conversation.