Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

laravel - 404未找到Laravel路由(404 NOT FOUND laravel routing)

what's wrong with my routes?

(我的路线怎么了?)

it cant redirect to my edit-info form inside InfosController

(它无法重定向到InfosController内的我的edit-info表单)

web.php

(web.php)

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

info-admin.blade.php

(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

(InfosController @编辑)

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

what did i do wrong, why laravel cant find my routes?

(我做错了什么,为什么拉拉维尔(Laravel)找不到我的路线?)

  ask by Bagas Kurniawan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

(除了使用硬编码之外,还可以像在编辑链接上使用destroy一样使用route。)

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

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

(要检查路由定义是否正确,请尝试在项目中运行。)

php artisan route:list

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...