0

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?

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

3 Comments

hello i want to ask again, why it's show me the undefined variables when i want to submit the update? i already edited my question
You can't just update the whole original question as the answer will become irrelevant. Create a new one and i will happily look at it, and link it here :)
well i need to wait 90min thats why i tried to edit the whole thing
0

There are multiple ways by which you can accomplish this:

<a href="{{action('InfosController@edit',$infos->id)}}">Edit</a>
<a href="{{ url('/info-admin/{$info}/edit'') }}">Edit</a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.