Home > Software engineering >  How do I show a picture on different pages using Laravel Route Prefix?
How do I show a picture on different pages using Laravel Route Prefix?

Time:03-12

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  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/...

CodePudding user response:

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

<img src="{{ asset('bar.jpg') }}" /> 
  • Related