Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I show a picture on different pages using Laravel Route Prefix?

I have a image file. More than one pages is using this image file.
Image is properly displayed in dashboard. Because this page not use Route Prefix.
For example; Brand page is using Route Prefix. The picture is not displayed on this page.

Route::middleware(['auth'])->group(function () {
Route::get('dashboard', [homeAppController::class, 'dashboard'])->name('dashboard');

//web.php
Route::controller(brandController::class)->group(function () {
    Route::group(['prefix' => 'brand', 'as' => 'brand.'], function () {
        Route::get('/', 'index')->name('index');
        Route::get('/create', 'create')->name('create');
        Route::get('/store', 'store')->name('store');
        Route::get('/show/{id}', 'show')->name('show');
        Route::get('/edit/{id}', 'edit')->name('edit');
        Route::get('/update/{id}', 'update')->name('update');
        Route::get('/destroy/{id}', 'destroy')->name('destroy');
    });
});

//Dashboard
<img alt="" src="../assets/media/svg/brand-logos/{{ $data->logo }}"/>

//brand/show    
<img class="rounded-0" src="../assets/media/svg/brand-logos/{{ $brand->logo }}" alt=""/>

The picture is not displayed on this page. Because route started with brand prefix. For example; …/brand/assets/…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is happening cause you are using relative paths, so it would be different on routes.

You can use full url like foo.com/bar.jpg
or Simply just /bar.jpg (starting / is important)

or if you’re on Laravel blade, you can also use

asset('bar.jpg')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading