我使用laravel,我需要通过路由传递参数到控制器。用get传递它们是有效的,但传递带有post的参数不起作用......
我有以下路线
Route::get('/ticket-read/{id}', ['uses' => 'TransactionController@show']);
Route::post('/ticket-create/{id}', ['uses' => 'TransactionController@insertTransaction']);
以下是控制器功能:
public function show($id){
echo $id;
}
public function insertTransaction($id){
echo $id;
}
问题:get方法正常工作,而post方法不起作用,导致以下错误:
C:\Laravel\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php
if ($request->method() == 'OPTIONS') {
return (new Route('OPTIONS', $request->path(), function () use ($methods) {
return new Response('', 200, ['Allow' => implode(',', $methods)]);
}))->bind($request);
}
$this->methodNotAllowed($methods);
}
/**
* Throw a method not allowed HTTP exception.
*
* @param array $others
* @return void
*
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
/**
* Get routes from the collection by method.
*
* @param string|null $method
* @return array
*/
public function get($method = null)
{
return is_null($method) ? $this->getRoutes() : Arr::get($this->routes, $method, []);
}
/**
* Determine if the route collection contains a given named route.
*
* @param string $name
* @return bool
*/
public function hasNamedRoute($name)
Arguments
""
Environment & details:
GET Data empty
POST Data empty
Files empty
Cookies
XSRF-TOKEN
"eyJpdiI6InBtSGhBWVQ4UElxVGlaeDJnM1lZaWc9PSIsInZhbHVlIjoia3ZYTXEyUDRPeG5cL0pNeGZ6aWFhSlVBZDZkSkFLZHB1akhRWG5FUTZLWmhGSWVpQ2JROWI2em5VaUpiXC9sUnMxazhMQkRXNUZFUjJF ▶"
laravel_session
"eyJpdiI6IlpwSXdneTc3NThwSDJMTUZFdlUrM1E9PSIsInZhbHVlIjoiMDdDNHROYnpoTlhzTTFOUlRQbmVcL0V4bHFsbnRGMXUxWGlcL3VnaVlIVGcrWjBteGJoaW9vclE1ZFwvWWphNlNkU0RlclwvSUFQblhw ▶"
Session empty
Server/Request Data
DOCUMENT_ROOT
"C:\Laravel\public"
REMOTE_ADDR
"127.0.0.1"
REMOTE_PORT
"27644"
SERVER_SOFTWARE
"PHP 7.1.9 Development Server"
SERVER_PROTOCOL
"HTTP/1.1"
SERVER_NAME
"127.0.0.1"
SERVER_PORT
"8000"
REQUEST_URI
"/ticketCreate/3"
REQUEST_METHOD
"GET"
SCRIPT_NAME
"/index.php"
SCRIPT_FILENAME
"C:\Laravel\public\index.php"
PATH_INFO
"/ticketCreate/3"
PHP_SELF
"/index.php/ticketCreate/3"
HTTP_HOST
"127.0.0.1:8000"
HTTP_USER_AGENT
"Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0"
HTTP_ACCEPT
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
HTTP_ACCEPT_LANGUAGE
"en-US,en;q=0.5"
HTTP_ACCEPT_ENCODING
"gzip, deflate"
HTTP_COOKIE
"XSRF-TOKEN=eyJpdiI6InBtSGhBWVQ4UElxVGlaeDJnM1lZaWc9PSIsInZhbHVlIjoia3ZYTXEyUDRPeG5cL0pNeGZ6aWFhSlVBZDZkSkFLZHB1akhRWG5FUTZLWmhGSWVpQ2JROWI2em5VaUpiXC9sUnMxazhMQ ▶"
HTTP_CONNECTION
"keep-alive"
HTTP_UPGRADE_INSECURE_REQUESTS
"1"
REQUEST_TIME_FLOAT
1518694286.8524
REQUEST_TIME
1518694286
Environment Variables empty
Registered Handlers
0. Whoops\Handler\PrettyPageHandler
note that it shows me the following message: REQUEST_METHOD "GET", while I'm using post in the Route, so what it should be the reason?
答案 0 :(得分:1)
你需要改变你在控制器内部做的回报,尝试这样的事情:
module pk.training.basit {
exports pk.training.basit;
requires transitive javafx.controls;
opens css;
}