Error entering URLs

0

You see, in the code my user bar I have added this:

@if(auth()->user())
<img class="card-img-top" style="width: 50px; height: 50px;" src="{{auth()->user()->ruta()}}"/>
@endif

The route function refers to this code in User.php:

public function ruta(){
    return "storage/".$this->foto;
}

Thanks to this, when a user connects, his picture appears.

However, in certain links the image fails.

It seems that being a url something more complex causes error. In fact, I can fix it with this change in the route method:

public function ruta(){
    return "/bolsa/public/storage/".$this->foto;
}

However it is a good billet, so I would like to know how to put the route relative. Also, being on that problematic route I see myself with another hurry. Among the icons I have another called "change image".

But if I do it from the complex url, I see myself with this.

Provisionally fix it by adding the url function in the href:

<a class="nav-link" href="{{ url('/cambiar_foto') }}">Cambiar imagen</a>

Although it will now have its fabric put "url" at each view. Is there a simpler way?

    
asked by Miguel Alparez 03.05.2018 в 22:06
source

1 answer

2

Well one of the things that I see is that you are directly accessing the public route to be able to use the Laravel project, and from there you will always have some details of routes to be accessed in that way. I propose the following to see that your data is showing correctly.

Open the windos console and see where you have your project folder, for example cd C:\Xammp\htdocs\miProyecto .

Once inside your project run the service that laravel brings by default to test your project php artisan serve when doing the command you will run the application to access it in your browser enter with the following path http://127.0.0.1:8000 already with that you will be able to test what I had in the beginning since using url brings you the relative route of the project if I remember correctly then in your blade you will be able to do the following

<img class="card-img-top" style="width: 50px; height: 50px;" src="{{ url('storage/'.auth()->user()->foto)}}"/>

and with this you should show the images well depending on how you are saving them in storage.

Now if you are using XAMPP an easy way is to create virtual hosts, so you can access your project in a simple way mipaginaweb.com for example.

CONFIGURE XAMPP

Configure windows host

  • Open the notebook as administrator
  • You open the hosts file located in C: \ Windows \ System32 \ drivers \ etc *
  • You will see your host's name resolution add this line
  • 127.0.0.1 mipaginaweb.com

    or whatever you want to call your virtual domain

    Configure Xampp's httpd-vhosts

  • From the same notebook you open the link file located at C: \ xampp \ apache \ conf \ extra
  • You add the following

    <VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/bolsa/public/" ServerName mipaginaweb.com </VirtualHost>

  • Restart the xammp service and you can access the path mipaginaweb.com directly

  • answered by 03.05.2018 в 23:34