Skip to content

Commit

Permalink
fix rss item last synced at bug
Browse files Browse the repository at this point in the history
  • Loading branch information
saber13812002 committed Jul 23, 2024
1 parent 746545f commit 2591f77
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/Models/RssItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;

class RssItem extends Model
{
use HasFactory;
use \Spatie\Tags\HasTags;

protected static function boot()
{
parent::boot();

static::creating(function ($model) {
$model->last_synced_at = $model->last_synced_at ?? Carbon::now()->format('Y-m-d');
});
}

protected $casts = [
'last_synced_at' => 'datetime:Y-m-d',
];
Expand Down
6 changes: 5 additions & 1 deletion app/Nova/RssItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\CarbonInterval;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
Expand Down Expand Up @@ -62,6 +63,9 @@ public function fields(NovaRequest $request)
Number::make('interval_minutes'),

DateTime::make('last_synced_at')
->default(function () {
return Carbon::now()->format('Y-m-d');
})
->withMeta(['extraAttributes' => [
'readonly' => true
]]),
Expand Down Expand Up @@ -126,7 +130,7 @@ public static function indexQuery(NovaRequest $request, $query): \Illuminate\Dat
{
$user = $request->user();

return $query->whereHas('rssBusiness', function($query) use ($user) {
return $query->whereHas('rssBusiness', function ($query) use ($user) {
$query->where('admin_user_id', $user->id);
});
}
Expand Down

0 comments on commit 2591f77

Please sign in to comment.