编辑:所以我改变了我的问题的标题。它是:内置用户迁移的时间戳与我们在Laravel中创建的其他迁移不同?如何将碳日期类型更改为字符串?
好的,这是事情。 Laravel开箱即可实现用户迁移。所以我没有创建任何。我需要一张发票表,所以我为此进行了迁移。这里有两个:
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
发票迁移:
class CreateInvoicesTable extends Migration
{
public function up()
{
Schema::create('invoices', function (Blueprint $table) {
$table->unsignedInteger('id')->unique();
$table->unsignedInteger('user_id')->index();
$table->longText('url');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('invoices');
}
}
我把一些初始数据存在。现在当我vardump created_at为他们每个人我得到不同的结果!我只是测试像下面,结果是:
foreach ($users as $user)
{
return var_dump($user->created_at);
}
结果是:
object(Carbon\Carbon)#185 (3) { ["date"]=> string(19) "2015-11-08 14:50:29" ["timezone_type"]=> int(3) ["timezone"]=> string(11) "Asia/Tehran" }
但是对于发票:
foreach ($invoices as $invoice)
{
return var_dump($invoice->created_at);
}
我得到这个:
string(19) "2015-11-09 11:15:55"
现在我并不在意为什么。如何将用户时间戳created_at更改为字符串。因为我有一个日期转换功能,可以在发票或任何其他数据上完美工作,但对于用户,我会收到错误。
任何帮助,将不胜感激。非常感谢你。
看看你的车型,看看有什么差异有比一些可填写的,受保护和隐藏的变量定义我没有看到任何其他的差异等有 –
@MarkBaker。 –
https:// laracasts。com/series/laravel-5-fundamentals/episodes/11 – sandeepsure