未捕获错误:Ziggy错误:路径不在路径列表中 [英] Uncaught Error: Ziggy error: route 'batch.run' is not in the route list

查看:0
本文介绍了未捕获错误:Ziggy错误:路径不在路径列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个Laravel8博客演示应用程序来学习Laravel8的细节。然而,在创建了一个新的控制器(PostsController的副本称为BatchesController)并将资源添加到web.php之后,只有默认的路径可以工作,比如编辑/创建/销毁。我尝试添加新的路由,但得到以下错误:&Quot;未捕获错误:Ziggy错误:路由‘Batch.run’不在路由列表中。

Batch.run是我的新路径,它几乎是已经为删除帖子而设置的&de";路径的副本。我不知道我做错了什么,因为我只是简单地使用与默认路由几乎相同的路由。在使用web.php中的Cover-All";资源";时,这些路由从哪里获得";添加";。难道它不应该根据路由的名称在控制器中运行任何方法吗?

这是我的web.php:

    Auth::routes(['verify' => true]);

Route::get('login', [LoginController::class, 'showLoginForm'])->name('showLoginForm')->middleware('guest');
Route::get('register', [RegisterController::class, 'showRegisterForm'])->name('showRegisterForm')->middleware('guest');

Route::post('login', [LoginController::class, 'authenticate'])->name('login');
Route::post('register', [RegisterController::class, 'register'])->name('register');

Route::post('logout', [LoginController::class, 'logout'])->name('logout');

Route::resource('post', PostsController::class);
Route::resource('batch', BatchesController::class);
Route::resource('token', TokensController::class);
Route::resource('home', HomeController::class);

Route::redirect('/', 'home');

以下是我的控制器方法:

    public function run(Request $request, $id) {
    Batch::find($id)->run();
    $request->session()->flash('success', 'Batch run successfully!');
    return redirect()->route('batch.running');
}

这是我的.VUE文件(不含模板):

数据-lang="js"数据-隐藏="假"数据-控制台="真"数据-巴贝尔="假">
<script>
import AppHeader from "../../Partials/AppHeader";
import ErrorsAndMessages from "../../Partials/ErrorsAndMessages";
import {usePage} from "@inertiajs/inertia-vue3";
import {Inertia} from "@inertiajs/inertia";
import {computed, inject} from "vue";

export default {
    name: "Batches",
    components: {
        ErrorsAndMessages,
        AppHeader
    },
    props: {
        errors: Object
    },
    setup() {
        const route = inject('$route');

        const deleteBatch = (id) => {
            if (!confirm('Are you sure want to delete #' + id + '?')) return;
            Inertia.delete(route('batch.destroy', {id}));
        }

        const runBatch = (id) => {
            if (!confirm('Are you sure you want to run #' + id + '?')) return;
            Inertia.post(route('batch.run', {id}));
        }

        const batches = computed(() => usePage().props.value.batches);

        const numberLinks = batches.value.links.filter((v, i) => i > 0 && i < batches.value.links.length - 1);

        return {
            batches,
            deleteBatch,
            runBatch,
            numberLinks
        }
    }
}
</script>

<style scoped>
    .action-btn {
        margin-left: 12px;
        font-size: 13px;
    }

    .article {
        margin-top: 20px;
    }

</style>

推荐答案

尝试为路由命名。

Route::get('gifts/list','GiftsController@list')->name("gifts.list");

并使用ROUTE函数调用该路由

 let listUrl = route("gifts.list");

以上解决了我的问题。

这篇关于未捕获错误:Ziggy错误:路径不在路径列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆