Home > OS >  My Laravel Links keep breaking Each time I restart my server
My Laravel Links keep breaking Each time I restart my server

Time:11-17

My Laravel links keep breaking each time I restart my local server

So, I am using Laravel 9 and my links keep breaking each time I reload the page or when I restart the server For example

127.0.0.1:8000/cars/1/edit

will become 127.0.0.1:8000/cars/cars/1/edit next time I click it.

I have searched for a solution and stumbled upon this Resouce route

For that reason, I'm finding it difficult to implement the route() solution proposed as his had a named route name

The href I want to make changes to looks like this. I am using resources routes in web.php

<a href="cars/{{ $car['id'] }}/edit">Edit &rarr;</a>

Href I want to edit

CodePudding user response:

You should use the route() helper. They are named to their corresponding method. since you are using route resource only the seven below will work

route('cars.index');
route('cars.create');
route('cars.store');
route('cars.edit');
route('cars.show');
route('cars.update');
route('cars.create');

<a href="{{ route('cars.edit', ['car' => $car['id']]) }}"></a>

CodePudding user response:

try this :


<a href='{{ url("cars/".$car['id']."/edit") }}'> edit </a>

CodePudding user response:

You can try something like this:

<a href="<?php echo route('cars', ['id' => $car['id'])?>">Edit</a>

Or:

<a href="{{ url('cars' , [ 'id' => $car->id ]) }}/edit"
  • Related