使用路线Laravel5.7路由:匹配不工作

问题描述 投票:1回答:3

我使用Laravel 5.7我想我的路由功能GET和POST。我想加载一个视图,后一种形式。正如我已经研究

Route::match(['GET','POST'], '/', TestController@test);
Route::any('/', TestController@test);`

其中之一应该工作。

但它不工作对我来说,有没有其他的办法还是我做错了什么?

UPDATE

路线管理:

Route::match(['get','post'], 'cp/', 'AdminController@test');

功能的管理控制器:

public function test( Request $request){

    $data=array();

    if ($request->isMethod('POST')) {
        echo "here it is";
        exit;
    }else{ 
        echo "still in get!";
    }
    return view('admin/login',  $data);
}

而我在很短的看法是这样的:

<form  action="{{ url('/cp') }}" method="POST">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
<form>
laravel laravel-5 login laravel-routing
3个回答
3
投票

你可以尝试改变

Route::match(['GET','POST'], '/', TestController@test);

Route::match(['GET','POST'], '/', 'TestController@test');

要么

Route::any('/', TestController@test);

Route::any('/', 'TestController@test');

第二PARAM应该被包裹在报价!

更新:

你的路由匹配的代码应该是这样的:

Route::match(array('GET', 'POST', 'PUT'), "/", array(
    'uses' => 'Controller@index',
    'as' => 'index'
));

1
投票

试试这个你web.php

Route::match(['get', 'post'], '/testMethods', function () 
{
    dd('its workong bro');
});

并击中yourprojectname/testMethods在Web浏览器

例如:http://localhost:8000/testMethods

Illuminate\Contracts\Routing\Registrar.php

public function match($methods, $uri, $action);

下面是匹配函数的参数列表

参数一个的方法列表:例如:GET,POST,放,补丁

参数网址:例如:/测试方法

参数三法:如:@的TestController测试

Route::match(['get', 'post'], '/testMethods','TestController@test');

0
投票

好了,年底我的理解使用route::match我应该没有它指定函数名,当我改变了它不会work.So它Route::match(array('GET', 'POST', 'PUT'), "/login", array( 'uses' => 'AdminController@login', 'as' => 'login' ));它解决了问题。感谢大家的帮助!

© www.soinside.com 2019 - 2024. All rights reserved.