Search code examples
laravellaravel-5laravel-routing

404 not found laravel routing


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','InfosController@edit');

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

InfosController@edit

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

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


Solution

  • You route is defined wrong.

    route::get('/info-admin/{$info}/edit','InfosController@edit');
    

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

    route::get('/info-admin/{info}/edit','InfosController@edit')->name('infos.edit');
    

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

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

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

    php artisan route:list