表格:
@section('form')
<div class="col-sm-4">
{!! Form::open() !!}
<div class="form-group">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', 'Enter your name', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('contact', 'Contact Number:') !!}
{!! Form::text('contact', 'Enter your contact number', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('location', 'Location:') !!}
{!! Form::select('location', $locations, null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('service', 'Service Required:') !!}
{!! Form::select('service', $services, null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Just go Befikr >>', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
</div>
@stop
路由.php:
<?php
Route::get('/', 'PagesController@index');
Route::post('/', 'PagesController@store');
PagesController.php
<?php namespace App\Http\Controllers;
use App\service_location;
use App\service_type;
use App\service_request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Request;
class PagesController extends Controller {
public function index()
{
$locations = service_location::lists('location_area', 'location_id');
$services = service_type::lists('service_desc', 'service_id');
return view('home.index', compact('locations','services'));
}
public function store()
{
$input = Request::all();
return $input;
}
}
不幸的是,代码似乎既没有在屏幕上返回 $input
(暗示它根本没有执行 store()
函数),也没有抛出任何异常错误/异常。
谁能告诉我为什么 post
方法在这里没有产生适当的结果?
编辑 1
我试图通过 route
的内联函数直接 return
,但即使这样也行不通。因此,现在我非常确信 post
方法根本不会被触发。这是我为验证它所做的:
Route::post('/', function()
{
return 'Hello';
});
最佳答案
好吧,我在这里找到了我自己的问题的答案。
事实证明,为了能够执行 post
请求,您需要显式部署一个 PHP 服务器:
php -s localhost:<AnyFreePort> -t <YourRootDirectory>
而当我第一次尝试通过 XAMPP 运行它时,我纯粹出于懒惰而试图运行该应用程序,直接如下:
http://localhost/myproject/public
对于 get
请求来说效果很好。
关于php - Post 方法在 Laravel 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29398323/