如果 <a> 标签中的路由什么都不做,则控制器只能从表单中工作

the controller only works from the form, if the route in the <a> tag does nothing

comment-reject 和其他类似路由没有进入控制器并且没有更改数据库中的记录,这是什么问题?当路由写在表单的action属性中时,一切正常。

comments.blade.php

@extends('dashboard')
@section('content')
    <div class="comments-block">
        @if($comments)
            @foreach ($comments as $comment)
                @if ($comment->parent_id != 0)
                    <p> {{ $comments[$comment->parent_id-1]->name }}</p>
                @endif
            <div class="comment-block-actions">
                <h1>{{$comment->text}}</h1>
                <a class = "approve-comment" href="{{ route('comments-approving', $comment->id) }}">approve</a><br/>
                <a class = "reject-comment" href="{{ route('comments-rejecting', $comment->id) }}">reject</a><br/>
                <a class = "delete-comment" href="{{ route('comments-deleting', $comment->id) }}">delete</a><br/>
            </div>
            @endforeach
        @endif
    </div>
@endsection

web.php

    Route::post('/commend-approved-{id}', [admin\adminController::class, 'approveComment'])->name('comments-approving');
    Route::post('/comment-rejected-{id}', [admin\adminController::class, 'rejectComment'])->name('comments-rejecting');
    Route::post('/comment-deleted-{id}', [admin\adminController::class, 'deleteComment'])->name('comments-deleting');

adminCOntroller.php

    public function approveComment($id)
    {
        $comment = comments::find($id);
        $comment->status = 'publish';
        $comment->save();
    }

    public function rejectComment($id)
    {
        $comment = comments::find($id);
        $comment->status = 'pending';
        $comment->save();
    }

    public function deleteComment($id)
    {
        comments::find($id)->delete();
    }```

这是行不通的,因为使用了其他路线,要修复这个我需要移动这个 3 路由到文件顶部

之前:

Route::prefix("/home")->group(function () {

         
    Route::get('/posts', [admin\adminController::class, 'viewPosts'])->name('posts');
    Route::get('/posts/edit-{id}', [admin\adminController::class, 'editPost'])->name('editPost');
    Route::post('/posts/edit-{id}', [admin\adminController::class, 'editPostPublish'])->name('editPostPublish');
    Route::get('/posts/new-post', [admin\adminController::class, 'postForm'])->name('postForm');
    Route::post('/posts/new-post/success', [admin\adminController::class, 'postPosting'])->name('postPosting');
    Route::get('/new-city', [admin\adminController::class, 'cityForm'])->name('cityForm');
    Route::post('/new-city/success', [admin\adminController::class, 'cityPost'])->name('cityPost');
    Route::get('/comments', [admin\adminController::class, 'viewComments'])->name('comments-view');
    Route::get('/category/new', [admin\adminController::class, 'newCategory'])->name('new-categories');
    Route::get('/taxonomy/new', [admin\adminController::class, 'newTaxonomy'])->name('new-taxonomy');
    Route::post('/success-cat', [admin\adminController::class, 'postCategory'])->name('success-cat');
    Route::post('/success-tax', [admin\adminController::class, 'postTaxonomy'])->name('success-tax');
    Route::get('/{postType}', [admin\adminController::class, 'viewAdvertisement'])->name('view-advertisement');
    Route::get('/{postType}/{id}', [admin\adminController::class, 'editAdvertisement'])->name('edit-advertisement');
    Route::post('/{postType}/{id}/success', [admin\adminController::class, 'editAdvertisementSuccess'])->name('success');
    Route::post('/{id}', [admin\adminController::class, 'deleteAdvertisement'])->name('delete-adv');
    Route::get('/commend-approved-{id}', [admin\adminController::class, 'approveComment'])->name('comments-approving');
    Route::get('/comment-rejected-{id}', [admin\adminController::class, 'rejectComment'])->name('comments-rejecting');
    Route::get('/comment-deleted-{id}', [admin\adminController::class, 'deleteComment'])->name('comments-deleting');

});

之后:

Route::prefix("/home")->group(function () {

    Route::get('/commend-approved-{id}', [admin\adminController::class, 'approveComment'])->name('comments-approving');
    Route::get('/comment-rejected-{id}', [admin\adminController::class, 'rejectComment'])->name('comments-rejecting');
    Route::get('/comment-deleted-{id}', [admin\adminController::class, 'deleteComment'])->name('comments-deleting');
    Route::get('/posts', [admin\adminController::class, 'viewPosts'])->name('posts');
    Route::get('/posts/edit-{id}', [admin\adminController::class, 'editPost'])->name('editPost');
    Route::post('/posts/edit-{id}', [admin\adminController::class, 'editPostPublish'])->name('editPostPublish');
    Route::get('/posts/new-post', [admin\adminController::class, 'postForm'])->name('postForm');
    Route::post('/posts/new-post/success', [admin\adminController::class, 'postPosting'])->name('postPosting');
    Route::get('/new-city', [admin\adminController::class, 'cityForm'])->name('cityForm');
    Route::post('/new-city/success', [admin\adminController::class, 'cityPost'])->name('cityPost');
    Route::get('/comments', [admin\adminController::class, 'viewComments'])->name('comments-view');
    Route::get('/category/new', [admin\adminController::class, 'newCategory'])->name('new-categories');
    Route::get('/taxonomy/new', [admin\adminController::class, 'newTaxonomy'])->name('new-taxonomy');
    Route::post('/success-cat', [admin\adminController::class, 'postCategory'])->name('success-cat');
    Route::post('/success-tax', [admin\adminController::class, 'postTaxonomy'])->name('success-tax');
    Route::get('/{postType}', [admin\adminController::class, 'viewAdvertisement'])->name('view-advertisement');
    Route::get('/{postType}/{id}', [admin\adminController::class, 'editAdvertisement'])->name('edit-advertisement');
    Route::post('/{postType}/{id}/success', [admin\adminController::class, 'editAdvertisementSuccess'])->name('success');
    Route::post('/{id}', [admin\adminController::class, 'deleteAdvertisement'])->name('delete-adv');


});```