Ad

404 Not Found Laravel Routing

- 1 answer

what's wrong with my routes? it can't redirect to my edit-info form inside InfosController

web.php

route::get('/info-admin/{$info}/edit','[email protected]');

info-admin.blade.php

@foreach ( $info as $infos )
                <tr>
                <th scope="row" class="align-middle">{{ $loop->iteration }}</th>
                <td class="align-middle">{{ $infos->judul }}</td>
                <td class="align-middle">{{ $infos->konten }}</td>
                <td class="align-middle">{{ $infos->image }}</td>
                <td class="align-middle">{{ $infos->created_at }}</td>
                <td class="align-middle">{{ $infos->Updated_at }}</td>
                <td class="align-middle form">
                <a target="_blank" rel="nofollow noreferrer" href="/info-admin/{{ $infos->id }}/edit"><button type="submit" class="btn btn-info mb-3">Edit</button></a>
                    <form method="POST" action="{{ route('infos.destroy', [$infos->id]) }}">
                        {{ csrf_field() }}
                        {{ method_field('DELETE') }}
                        <button type="submit" class="btn btn-danger">Hapus</button>
                    </form>
               </td>
           </tr>
@endforeach

[email protected]

public function edit($id)
    {
        return view('admin.edit-info');
    }

what did I do wrong, why laravel can't find my routes?

Ad

Answer

You route is defined wrong.

route::get('/info-admin/{$info}/edit','[email protected]');

Should be without $ and name the route for easier linking.

route::get('/info-admin/{info}/edit','[email protected]')->name('infos.edit');

Instead of hard coding it, use route as you do with destroy on the edit link too.

<a target="_blank" rel="nofollow noreferrer" href="{{ route('infos.edit', [$infos->id]) }}">

To check if you routes are defined correctly, try running in the project.

php artisan route:list
Ad
source: stackoverflow.com
Ad