PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 6, 2022

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

 May 06, 2022     image, laravel, prefix, routes, url     No comments   

Issue

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


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

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


Answered By - Aniket Das
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing