我遇到错误“ InvalidArgumentException跟踪数据”

时间:2019-12-16 11:50:08

标签: php mysql laravel

嗨,我尝试了我在Google上发现的所有内容,但没有任何效果,当我尝试在数据库中插入日期时,总是出现错误跟踪数据的情况。我希望有一个人可以帮助我。非常感谢,对不起我的英语。

//这是我的模特位置

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Location extends Model
{
    protected $table = 'location';

}

//这里是我的迁移

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class Location extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('location', function(Blueprint $table) {
            $table->bigIncrements('id');
            $table->date('start');
            $table->date('end');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('location');
    }
}

//这是将日期存储在控制器中的方法

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Location;
use Carbon\Carbon ;
    public function storeDate(Request $request){

        $location = new Location();

        $start  = Carbon::createFromFormat('m/d/y', $request->input("start"));
        $end  = Carbon::createFromFormat('m/d/y', $request->input("end"));

        $location->start = $start;
        $location->end = $end;

        $location->save();

        return redirect('/myCar');

    }
}

我的表格

 <form class="form-inline" method="POST" action="/storedate">
              @csrf
              <div class="modal-body">           
                <label class="sr-only" for="inlineFormInputName2"></label>
                <input type="text" class="form-control mb-2 mr-sm-2" id="inlineFormInputName2" placeholder="dd/mm/yyyy" value="20/04/2019" name="start">         
                <label class="sr-only" for="inlineFormInputGroupUsername2"></label>
                <div class="input-group mb-2 mr-sm-2">
                  <input type="text" class="form-control" id="inlineFormInputGroupUsername2" placeholder="dd/mm/yyyy" value="20/04/2019" name="end">
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="submit" class="btn btn-primary">Send message</button>
              </div>
            </form>

1 个答案:

答案 0 :(得分:0)

好的,我找到了。在m/d/y中,我的 y 必须大写:

  

m / d / Y

谢谢您的支持!