user12855055
user12855055

Reputation:

how to pass the variable to the input?

I have this code in my blade:

@php
    $images_products = $product->images()->where('main_image', 0)->get();

    foreach ($images_products as $image) {

        $preloadedFiles[] = [
            "name"  => $image->image,
            "type"  => FileUploader::mime_content_type($image->image_path),
            "size"  => filesize('uploads/products/'. $image['image']),
            "file"  => $image->image_path,
            "local" => $image->image_path,
        ];

    }
@endphp

{{-- @dd(json_encode($preloadedFiles)) --}}

<input type="file" name="images" data-fileuploader-files="{{ json_encode($preloadedFiles) }}">

I got the error:

Undefined variable: preloadedFiles

but when I do the dd for same variable it's work!!

Upvotes: 0

Views: 39

Answers (1)

Foued MOUSSI
Foued MOUSSI

Reputation: 4813

@php
    $images_products = $product->images()->where('main_image', 0)->get();

    // Just initialize empty $preloadedFiles array here
    $preloadedFiles = [];

    foreach ($images_products as $image) {

        $preloadedFiles[] = [
            "name"  => $image->image,
            "type"  => FileUploader::mime_content_type($image->image_path),
            "size"  => filesize('uploads/products/'. $image['image']),
            "file"  => $image->image_path,
            "local" => $image->image_path,
        ];

    }
@endphp

{{-- @dd(json_encode($preloadedFiles)) --}}

<input type="file" name="images" data-fileuploader-files="{{ json_encode($preloadedFiles) }}">

Upvotes: 1

Related Questions