Skip to content

Commit

Permalink
Update feature image url
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesPong committed Jan 29, 2018
1 parent 5b8dcf9 commit b003631
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
11 changes: 11 additions & 0 deletions app/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Scopes\PublishedScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Storage;
use Indigo\Contracts\Markdownable;
use Indigo\Tools\MarkDownParser;
use Laracasts\Presenter\PresentableTrait;
Expand Down Expand Up @@ -187,4 +188,14 @@ public function content()
{
return $this->belongsTo(Content::class);
}

/**
* @return string
*/
public function getFeatureImgUrlAttribute()
{
$value = $this->getAttribute('feature_img');

return starts_with($value, ['https://', 'http://']) ? $value : Storage::url($value);
}
}
32 changes: 0 additions & 32 deletions app/Presenters/PostPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,5 @@
*/
class PostPresenter extends Presenter
{
/**
* @return string
*/
public function selectedTags()
{
if (old('tag')) {
$tagArr = array_map(function ($tagName) {
return '"' . $tagName . '"';
}, old('tag'));

return implode(',', $tagArr);
}

return $this->tags->pluck('name')->map(function ($tagName) {
return '"' . $tagName . '"';
})->implode(',');
}

/**
* @return false|mixed|null|string
*/
public function publishedTime()
{
if ($old = old('published_at')) {
return $old;
}

if ($this->published_at) {
return date('m/d/Y g:i A', $this->published_at->timestamp);
}

return null;
}
}
2 changes: 1 addition & 1 deletion resources/views/widgets/post-card.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="card hoverable">
<div class="card-image">
<img src="{{ $post->feature_img }}">
<img src="{{ $post->feature_img_url }}">
<a class="btn-floating btn-large halfway-fab waves-effect waves-light materialize-red lighten-2"
href="{{ route('articles.show', $post->slug) }}">
<i class="material-icons">more_horiz</i>
Expand Down

0 comments on commit b003631

Please sign in to comment.