Skip to content

Commit

Permalink
Update Slideshow.php
Browse files Browse the repository at this point in the history
  • Loading branch information
bastihilger committed Jul 15, 2021
1 parent 574d58a commit 32169bb
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/Models/Slideshow.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Kraenkvisuell\NovaCmsPortfolio\Models;

use Kraenkvisuell\NovaCmsMedia\API;
use Spatie\EloquentSortable\Sortable;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
use Spatie\EloquentSortable\SortableTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Kraenkvisuell\NovaCmsMedia\API;
use Kraenkvisuell\NovaCmsPortfolio\Factories\SlideshowFactory;
use Kraenkvisuell\NovaCmsPortfolio\Traits\Publishable;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;
use Spatie\Translatable\HasTranslations;

class Slideshow extends Model implements Sortable
{
Expand All @@ -23,7 +23,7 @@ class Slideshow extends Model implements Sortable
'sort_when_creating' => true,
'sort_on_has_many' => true,
];

protected $guarded = [];

public function getTable()
Expand Down Expand Up @@ -87,6 +87,7 @@ public function workFilenames()
$filenames[] = API::getOriginalName($work->file);
}
ray($filenames);

return $filenames;
}

Expand All @@ -103,4 +104,24 @@ public function scopePresentableForOverview($builder)
$q->where('show_in_overview', true);
});
}

public function workForNews()
{
$markedWork = $this->works()
->where('show_in_overview', true)
->first();

if (! $markedWork) {
$markedWork = $this->works()->first();
}

return $markedWork;
}

public function workForDisciplineUrl($disciplineId)
{
$work = $this->workForDiscipline($disciplineId);

return $work && $work->file ? nova_cms_image($work->file) : null;
}
}

0 comments on commit 32169bb

Please sign in to comment.