我尝试了在 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');
}
}
宝慕林4294392