Update channels model to set default icon in the event that one doesn't exist, as described in #55

This commit is contained in:
Jason Williams 2020-10-28 16:54:22 -06:00
parent d3b4fd851b
commit a50c117a98
1 changed files with 39 additions and 33 deletions

View File

@ -1,33 +1,39 @@
<?php namespace jasonwilliams\feed\Models; <?php namespace jasonwilliams\feed\Models;
use Model; use Model;
/** /**
* Model * Model
*/ */
class Channels extends Model class Channels extends Model
{ {
use \October\Rain\Database\Traits\Validation; use \October\Rain\Database\Traits\Validation;
/* /*
* Disable timestamps by default. * Disable timestamps by default.
* Remove this line if timestamps are defined in the database table. * Remove this line if timestamps are defined in the database table.
*/ */
public $timestamps = false; public $timestamps = false;
/** /**
* @var string The database table used by the model. * @var string The database table used by the model.
*/ */
public $table = 'jasonwilliams_feed_channels'; public $table = 'jasonwilliams_feed_channels';
/** /**
* @var array Validation rules * @var array Validation rules
*/ */
public $rules = [ public $rules = [
]; ];
public $hasMany = [ public $hasMany = [
'feeditems' => ['jasonwilliams\feed\Models\FeedItem', 'key' => 'channel_id'] 'feeditems' => ['jasonwilliams\feed\Models\FeedItem', 'key' => 'channel_id']
]; ];
}
public function afterFetch()
{
// Add a default icon if there isn't one already
if (!$this->icon) $this->icon = "fas fa-sticky-note";
}
}