Uploading images via the Orchid Laravel library

506 Views Asked by At

I'm trying to upload an image from storage and insert it into the table. I tried a bunch of options for forming a path to a photo and none of them worked. Below are examples of paths.I work through WSL.

TD::make('image', 'Картинка')->render(function (News $news){
            return "<img src="{asset($news->image)}"";
            return  asset($news->image);
        }),

enter image description hereenter image description here

1

There are 1 best solutions below

3
On

I already read the Orchid documentation and it seems that you should use some built-in function for uploading files including images. This is an example from Orchid website:

use Orchid\Attachment\File;

public function upload(Request $request)
{
    $path = "photos"
    $image= new File($request->file('photo'));
    $attachment = $image->path($path)->load();

    return response()->json()
}

If you want to access your uploaded image then try this:

<img src="{{ asset('storage/photos/'.$image) }}" alt="{{ $image}}" class="some class">