如何在laravel 4.1上植入时间戳?

梅尔文伯德

美好的一天,

当我尝试播种我的数据库时,出现错误“日期时间类的对象无法转换为字符串”。

这是我的迁移代码:

    public function up()
{
    Schema::create('tblinventory', function(Blueprint $table) {
        $table->increments('id');
        $table->integer('itemId');
        $table->enum('status', array('active','inactive'))->default(null)->nullable();
        $table->float('purchasePrice');
        $table->float('sellingPrice');
        $table->date('expirationDate');
        $table->float('ReceivedQuantity');
        $table->float('soldQuantity');
        $table->timestamps();
    });
}

和我的播种机:

<?php

class InventoryTableSeeder extends Seeder {

public function run()
{
    // Uncomment the below to wipe the table clean before populating
    DB::table('tblinventory')->truncate();

    $insert = [
        [
        'itemId' => '1', 
        'status' => 'inactive',
        'ReceivedQuantity'=>'100',
        'SoldQuantity'=>'93',
        'sellingPrice'=>'4.5',
        'purchasePrice'=>'3.5',
        'created_at' => new DateTime,
        'expirationDate'=>date('2015-02-22')
        ],
        [
        'itemId' => '1', 
        'status' => 'inactive',
        'ReceivedQuantity'=>'300',
        'SoldQuantity'=>'300',
        'sellingPrice'=>'4.75',
        'purchasePrice'=>'3.65',
        'expirationDate'=>date('2015-02-22')
        ],
        [
        'itemId' => '2', 
        'status' => 'inactive',
        'ReceivedQuantity'=>'100',
        'SoldQuantity'=>'93',
        'sellingPrice'=>'3.5',
        'purchasePrice'=>'2.5',
        'expirationDate'=>date('2014-07-22')
        ],
        [
        'itemId' => '3', 
        'status' => 'inactive',
        'ReceivedQuantity'=>'100',
        'SoldQuantity'=>'93',
        'sellingPrice'=>'12.5',
        'purchasePrice'=>'10.5',
        'expirationDate'=>date('2017-01-02')
        ],
        [
        'itemId' => '3', 
        'status' => 'inactive',
        'ReceivedQuantity'=>'100',
        'SoldQuantity'=>'100',
        'sellingPrice'=>'14.5',
        'purchasePrice'=>'13.5',
        'expirationDate'=>date('2017-07-22')
        ],
        [
        'itemId' => '4', 
        'status' => 'inactive',
        'ReceivedQuantity'=>'100',
        'SoldQuantity'=>'93',
        'sellingPrice'=>'24.5',
        'purchasePrice'=>'23.5',
        'expirationDate'=>date('2015-07-22')
        ]

    ];

    DB::table('tblinventory')->insert($insert);
    // Uncomment the below to run the seeder
    // DB::table('inventories')->insert($inventories);
}

}

我放错了'created_at'=> new DateTime我怎样才能解决这个问题?谢谢!

安东尼奥·卡洛斯·里贝罗

尝试使用Carbon创建日期(Laravel在内部使用日期):

'expirationDate' => \Carbon\Carbon::createFromDate(2014,07,22)->toDateTimeString()

要么

'created_at' => \Carbon\Carbon::now()->toDateTimeString()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在LARAVEL 4上使用TCPDF

来自分类Dev

如何在Windows上安装Laravel 4软件包

来自分类Dev

如何在UnitTesting Laravel 4上模拟App :: make()

来自分类Dev

如何在远程服务器上管理Laravel 4

来自分类Dev

如何在Windows上安装Laravel 4软件包

来自分类Dev

Laravel 4-如何关闭时间戳以更新整个集合

来自分类Dev

Laravel 4时间戳格式

来自分类Dev

如何在Hive表中插入时间戳?

来自分类Dev

如何在Doobie(Postgres)中读取/写入时间戳

来自分类Dev

如何在Hive表中插入时间戳?

来自分类Dev

如何创建插入时间戳的选项?

来自分类Dev

有谁知道如何在Laravel 4上安装SASS?

来自分类Dev

Laravel 4,如何在Route :: controller()上应用过滤器

来自分类Dev

如何在Laravel 4上执行自定义auth :: attempt消息

来自分类Dev

如何在Laravel 4路由组上应用多个过滤器?

来自分类Dev

如何在laravel 4中批量更新

来自分类Dev

如何使用Bootstrap 4响应输入时间

来自分类Dev

如何将Javascript日期传递给laravel 4 API时间戳

来自分类Dev

如何将Javascript日期传递给laravel 4 API时间戳

来自分类Dev

如何在neo4j中通过时间戳过滤边缘?

来自分类Dev

如何在4个字节内保存日期时间戳

来自分类Dev

如何在 amcharts4 中将时间戳 unix 格式化为日期

来自分类Dev

如何在 Angular 2/4 中将当前日期转换为时间戳

来自分类Dev

Laravel 4,在雄辩的查询中省略时间戳

来自分类Dev

如何在laravel的unix时间戳中保存日期?

来自分类Dev

如何以容忍度加入时间戳列

来自分类Dev

如何在Rails 4上使用Ajax?

来自分类Dev

如何在Nexus 4上使用GPS?

来自分类Dev

ELK - 如何从日志文件中选择时间戳而不是插入时间戳

Related 相关文章

热门标签

归档