【问题标题】:Laravel Date/Time Carbon IssueLaravel 日期/时间碳问题
【发布时间】:2017-11-28 22:21:06
【问题描述】:

我正在开发考勤管理系统。

我的看法是这样的。

我需要的是如果我选择时间值并按下Mark here按钮当前数据和时间值需要根据受训者ID存储在数据库中。

这是视图。

   <table class="table table-striped">
        <thead>

           <th>Trainee ID</th>
           <th>Name with Initials</th> 
           <th>Time</th>
           <th>Mark Here!</th>

        </thead>

        <tbody>
        @foreach($items as $item)

          <tr>
             <td>
                <div class="form-group">
                <input type="text" name="trainee_id" class="form-control" value="{{ $item->trainee_id }}">
                </div>
             </td>

              <td>
                  {{ $item->name_with_initials }}
              </td>

              <td>
                    <label><input type="checkbox" name="time" id="time" value="time">&nbsp; Time</label>
              </td>

              <td>
                    <a class="btn btn-info" href="Bankdetails/{{ $item->trainee_id }}">Mark Here</a>
              </td>
          </tr>
      @endforeach 
      </tbody>

 </table>

我知道我的控制器完全没问题,需要修复。

 public function store(Request $request)
    {
        $queryType = $request->time;
        $carbon = new Carbon('queryType');
        attendancedetails::create($request->all());

        return view('traineeattendance.attendanceo');
    }

这是必要的数据模型。

class attendancedetails extends Model
{
    protected $table = "attendancedetails";
    protected $fillable = ['id',
    'attendance_date',
    'trainee_id',
    'name',
    'starting_time',
    'end_time',
    'site_visit_time'];
}

谁能建议我解决这个问题。

【问题讨论】:

  • 你确定,你的控制器是对的吗?你甩了$request-&gt;all() 吗?我认为使用$request-&gt;all() 创建不是一个好习惯。
  • $request->all() 用于将数据保存到数据库中。我的控制器不符合我的要求。所以我需要修复它
  • 您需要随时间增加用户出席率吗?您的请求只有受训者 ID,因此您如何添加您在模型中描述的其他详细信息
  • 那我该怎么做呢?你能推荐我吗?
  • 你遇到了什么错误,并在 $request->all() 中描述你的存储字段。

标签: php laravel datetime laravel-5


【解决方案1】:

你已经在 laravel 中默认设置了当前时间。当您在迁移中保存记录时,会有一个timestamps(); 输入:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        ...
        $table->timestamps();
    });
}

这会在您的数据库表中创建一个 created_atupdated_at 列!您可以使用created_at 保存输入的时间以在其他地方显示!

【讨论】:

  • create at 是解决这个问题..我怎样才能得到结束时间。我能通过更新时间 ryt 得到它吗?
  • updated_at time 是该行中的数据更新的时间。因此,如果这是您需要的,那么是的,您可以利用这段时间。但我仍然不确定你想达到什么目标!?
  • 我正在开发考勤管理系统。当学员来办公室时,我必须标记他/她的值班时间。以及他/她离开的时间也需要记录和检索。之前我创建了一个从填充数据然后保存到数据库中。但是主管要求我做我在屏幕截图中显示的事情。只需选择时间复选框然后发送它。根据该检索数据。
猜你喜欢
  • 2016-11-08
  • 2019-11-25
  • 1970-01-01
  • 1970-01-01
  • 2017-05-20
  • 1970-01-01
  • 2018-03-16
  • 2018-03-14
  • 2017-08-25
相关资源
最近更新 更多