skip to Main Content

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 On every click link changes in blade view

But the problem is that the guy that asked the question is using named routes from web.php route

I, on the other hand, am using resource routes ( I do not know what to call them = Route::resource('/cars', CarsController::class);)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

3

Answers


  1. try this :

    
    <a href='{{ url("cars/".$car['id']."/edit") }}'> edit </a>
    
    
    Login or Signup to reply.
  2. 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>
    
    Login or Signup to reply.
  3. 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"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search