25 lines
586 B
PHP
25 lines
586 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class KeywordHistory extends Model
|
|
{
|
|
protected $fillable = [];
|
|
protected $guarded = [];
|
|
|
|
public function addKeywordHistory($keyword, $user)
|
|
{
|
|
if (empty($user)) {
|
|
return;
|
|
}
|
|
$history = $this->firstOrCreate(['name'=>$keyword, 'user_id'=>$user->id]);
|
|
$history->updated_at = date('Y-m-d H:i:s');
|
|
$history->save();
|
|
$hot_keyword = HotKeyword::firstOrCreate(['name'=>$keyword]);
|
|
$hot_keyword->increment('num', 1);
|
|
return;
|
|
}
|
|
}
|