建立打卡記錄 timeRecord 模型
php artisan make:model Models/TimeRecord
編輯 timeRecord 模型
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class TimeRecord extends Model
{
protected $table = 'time_recored';
public $timestamps = false;
}
為user模型增加個方法
public function TimeRecord()
{
return $this->hasMany('App\Models\TimeRecord','user_id');
}
為usercontroller增加個方法
public function showRecord()
{
$data = User::find(1)->TimeRecord()->where('month','like','%2018-11%')->get();
$data = $this->Arr($data);//1v1中提到
print_r($data);
}