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
2.8k views
in Technique[技术] by (71.8m points)

php - How can I corrrect 404 NOT FOUND error, resulting from a view, route, controller scheme in Laravel 8?

I am seeing 404 NOT FOUND page after trying the code below,

Here is my blade code,

<a href="{{route('admin.delete.article',$article->id)}}" title="Delete" class="btn btn-sm btn-danger"><i class="fa fa-times"></i></a>

Here is my route, the route has a prefix called admin

Route::get('/deletearticle/{$id}','AppHttpControllersBackArticleController@delete')->name('delete.article');

Here is my controller class, which is initially generated as a resource, however for the purpose of deleting a row from the database, a new function called delete is introduced manually. Therefore I am not using the destroy function. I am not introducing a delete method yet, so that I can see the $id on a new page as a test.

class ArticleController extends Controller
{
    public function delete($id)
    {
        return $id;
    }

    public function destroy($id)
    {
        //
    }
}

As you can see above, I am not introducing a delete method yet so that I can see the $id on a new page.. Also when I hower the mouse on the delete link object and click on it, it shows me localhost:8000/admin/deletearticle/9 on the browser, which is correct. But the page is 404 NOT FOUND .

I would be greatful to hear from you, if you have an idea about this problem.


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

1 Answer

0 votes
by (71.8m points)

Route parameters don't have a $ in their name. {id} not {$id}.


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

...