← Previous · Back to README · Next →
Eloquent
Model saves automatically store Str::slug(title) in slug through SlugCast, using the final stored title after custom title setters. Custom title mutators and saveQuietly() are supported. Renaming the title changes the slug. For example, Products becomes products. Query Builder bulk updates and inserts bypass model saving; use model create(), update(), or save() instead.
Choose titles that produce distinct, non-empty slugs for selected and scheduled feeds. A title that normalizes to an empty slug cannot be selected. Multiple non-deleted registrations with the same slug cause Illuminate\Database\MultipleRecordsFoundException on lookup; no suffix is added automatically.
Custom feed registration model
Set feeds.model to an application model when feed registration records need additional columns, casts, relationships, or methods. The custom model must extend DragonCode\LaravelFeed\Models\Feed.
namespace App\Models;
use DragonCode\LaravelFeed\Models\Feed as BaseFeed;
class Feed extends BaseFeed
{
protected $fillable = [
'class',
'title',
'expression',
'is_active',
'last_activity',
'is_foo',
'is_bar',
];
protected function casts(): array
{
return [
...parent::casts(),
'is_foo' => 'boolean',
'is_bar' => 'boolean',
];
}
}
Register the model in config/feeds.php:
'model' => App\Models\Feed::class,
Add the custom columns to the feeds table in an application migration. Keep every attribute accepted by mass assignment in $fillable.
FeedQuery uses the configured model for create, find, list, update, delete, and restore operations. Pass application-specific values through extra when creating a record. These values are applied last and can override the method arguments:
$feed = app(FeedQuery::class)->create(
class: SomeFeed::class,
title: 'Some',
expression: '0 */12 * * *',
extra: [
'is_foo' => true,
'is_bar' => true,
]
);
The application model can also use the regular Eloquent API:
use App\Models\Feed;
$feed = Feed::create([
'class' => SomeFeed::class,
'title' => 'Some',
'expression' => '0 */12 * * *',
'is_active' => true,
'is_foo' => true,
'is_bar' => true,
]);
The configured model is resolved at runtime. Static analysis sees the result of FeedQuery::create() as the package base model. Use App\Models\Feed::create() or an explicit local type when autocomplete for application-specific properties is required.
Chunk size
Database queries use chunks, which are 1000 items by default. You can change this by overriding the chunkSize method:
use DragonCode\LaravelFeed\Feeds\Feed;
class UserFeed extends Feed
{
public function chunkSize(): int
{
return 500;
}
}