【发布时间】:2018-11-10 09:09:02
【问题描述】:
我有用户工作经验的自定义表格:
Schema::create('workplaces', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
$table->string('company')->nullable();
$table->string('position')->nullable();
$table->string('description')->nullable();
$table->smallInteger('from')->nullable();
$table->smallInteger('to')->nullable();
$table->timestamps();
});
这里是用户体验数据示例:
----------------------------------------------------------
| user_id | company | position | description | from | to |
----------------------------------------------------------
----------------------------------------------------------
| 1 | Google | Designer | Lorem ipsum | 2018 |null|
----------------------------------------------------------
----------------------------------------------------------
| 1 | Yahoo | Designer | Lorem ipsum | 2014 |2017|
----------------------------------------------------------
----------------------------------------------------------
| 1 |Microsoft| Designer | Lorem ipsum | 2004 |2008|
----------------------------------------------------------
在此示例中,id == 1 的用户拥有 7 年 工作经验。
2018 - (2017 - 2014) - (2008 - 2004) = 2011
用户去年在 2018 年工作,现在我需要从上一个工作年减去结果:
2018 - 2011 = 7
现在,当前用户有 7 年的工作经验。
如何使用 laravel eloquent 计算自定义工作经验?
【问题讨论】:
-
你想输出什么?你能解释一下吗?
-
@HamidNaghipour 我需要计算用户工作经验。在我的示例中,数据用户有 7 年的工作经验。我如何用 eloquent 计算它?
标签: laravel eloquent laravel-5.7