Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 拉威尔使路线自动化_Php_Laravel 5_Routes - Fatal编程技术网

Php 拉威尔使路线自动化

Php 拉威尔使路线自动化,php,laravel-5,routes,Php,Laravel 5,Routes,我在我的laravel应用程序中使用的一些路线如下: Route::get('/structure', 'Superuser\StructureController@index'); 所以,如果我转到localhost/myproject/structure,我将使用StructureController及其方法“index”。 现在我想使用其他功能,如添加、更新、删除、重新排序等。。。 有没有简单的方法,我不需要写: Route::get('/structure/add', 'Superu

我在我的laravel应用程序中使用的一些路线如下:

Route::get('/structure', 'Superuser\StructureController@index'); 
所以,如果我转到localhost/myproject/structure,我将使用StructureController及其方法“index”。 现在我想使用其他功能,如添加、更新、删除、重新排序等。。。 有没有简单的方法,我不需要写:

Route::get('/structure/add', 'Superuser\StructureController@add');
Route::get('/structure/update/{url}', 'Superuser\StructureController@update');
Route::get('/structure/delete/{url}', 'Superuser\StructureController@delete');

如果这是可能的,我想使用::get实现一切。非常感谢。

如果您想使用GET实现所有功能,我认为没有一种内置的自动方式可以做到这一点,不过您可以编写一个方法,根据传入的控制器名称吐出路由

有针对资源控制器的自动RESTful/Resourceful路由:

Route::resource('photos', 'PhotoController');
这将产生以下路线:

Actions Handled By Resource Controller
Verb    URI                    Action   Route Name
GET     /photos                index    photos.index
GET     /photos/create         create   photos.create
POST    /photos                store    photos.store
GET     /photos/{photo}        show     photos.show
GET     /photos/{photo}/edit   edit     photos.edit
PUT/PATCH   /photos/{photo}    update   photos.update
DELETE  /photos/{photo}        destroy  photos.destroy

谢谢您的回复。当我需要更多的路线时,我该怎么办?我甚至不知道,为什么我想用GET来处理所有事情,也许这对我的需求来说很简单。我也不太理解拉威尔我想…:(即使您使用Route::resource命令,也可以始终添加更多路由。但是,如果您不知道为什么要使用GET而不是POST,例如,这更像是一个基本的web应用程序概念,而不是laravel。建议您现在一次添加一条路由。获取您希望用户访问的地址。发布表单提交。大多数基本c您可以获取。您好。很抱歉,我再次打扰您。我尝试了上面的示例,但恐怕它不起作用。我遇到了错误。不需要使用artisan生成某些内容?我刚刚编写了“资源”控制器名为routes/web.php,不起作用。不需要使用artisan命令。为什么要描述代码行,而不是复制粘贴它?有人会更容易帮助您查看实际的代码行。当您说“不起作用”时,是否会出错?可能是命名空间问题。