我是新来的Laravel,我想透过这个框架的CRUD应用程序。但是,当每次我提出我不断收到此错误“法照亮\ HTTP \支持::日期不存在。”我无法将其存储到数据库。 Full Error Message Full Form Code
//blade template code
<div class="form-group col-lg-12">
{{Form::label('delivery_date', 'Delivery Date:')}}
{{Form::date('delivery_date', \Carbon\Carbon::now())}}
</div>
// controller code
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Customer;
use Carbon\Carbon;
class CustomersController extends Controller
{
public function store(Request $request)
{
$this->validate($request, [
'owner_name' => 'required',
'store_name' => 'required',
'address' => 'required',
'latitude' => 'required',
'longitude' => 'required',
'cluster' => 'required'
]);
// create customers
$customer = new Customer;
$customer->owner_name = $request->input('owner_name');
$customer->store_name = $request->input('store_name');
$customer->contact_no = $request->input('contact_no');
$customer->address = $request->input('address');
$customer->latitude = $request->input('latitude');
$customer->longitude = $request->input('longitude');
$customer->cluster = $request->input('cluster');
$customer->delivery_date = $request->date('delivery_date');
$customer->save();
return redirect('/customers')->with('success', 'Customer Added!');
}
}
答案 0 :(得分:0)
的表格::标签强>表达不使用任何更多。它在 Laravel 4 中使用,在 Laravel 5 中,有一个新的表单管理标准。
如果收到此错误,请在控制器的开头添加:
use Illuminate\Http\Request;
和然后形式HTML应
<form action="{{ route('customers.store') }}" method="POST">
@csrf
<div class="row">
<div class="form-group col-lg-12">
<label for="delivery_date">Delivery Date</label>
<input name="delivery_date" id="delivery_date" class="form-control" type="text">
</div>
</div>
<div class="row">
<div class="form-group col-lg-12">
<button type="submit" class="btn btn-primary float-right">Submit</button>
</div>
</div></form>
答案 1 :(得分:0)
没有$ request-> date()之类的东西,因此代码应该是
$customer->delivery_date = $request->input('delivery_date');
或如果需要日期值,则使用Carbon
答案 2 :(得分:0)
尝试此代码
$customer->delivery_date = $request->delivery_date;