Skip to main content

← Previous · Back to README · Next →

Eloquent

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,
]);
note

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;
}
}

See Also​