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

djmhdi's avatar

Acces to my public folder from controller

Hi :) I upload images to folder public/uploads/images , i want to display this image on datatables , so i use this code on my controller but it doesn't work

        ->addColumn('imageMostafid', function ($mostafid) {
            return '<img src="{!! url('/uploads/images/'.$mostafid->imageM) !!}" alt="mostafid" height="20" width="20">';
        })

I'm using laravel 5.4,Can you help me to resolve my problem ?

0 likes
11 replies
bunnypro's avatar

you can use asset() helper. change url() to asset().

1 like
djmhdi's avatar

Same result, it does not work

EmilMoe's avatar

What does your server log say?

1 like
djmhdi's avatar

Use of undefined constant uploads - assumed 'uploads'

bunnypro's avatar

ah, add \ then

'<img src="{!! url(\'/uploads/images/\'.$mostafid->imageM) !!}" .. >'
bunnypro's avatar

wait ..

why there is a blade syntax ? is this in a blade file ?

bunnypro's avatar
bunnypro
Best Answer
Level 7

you can refactor it to be

->addColumn('imageMostafid', function ($mostafid) {
    $url = url('/uploads/images/'.$mostafid->imageM);

    return "<img src='{$url}' alt='mostafid' height='20' width='20'>";
});

*edited

djmhdi's avatar

Thank you bunnypro, it's work perfectly

Please or to participate in this conversation.