Skip to content

Commit

Permalink
Refactor & libs update
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislawfortonski committed May 18, 2021
1 parent d822494 commit e7bf459
Show file tree
Hide file tree
Showing 17 changed files with 667 additions and 57,774 deletions.
12 changes: 2 additions & 10 deletions app/Models/AuthorContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace App\Models;

use App\Traits\HasDescription;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class AuthorContent extends Model
{
use HasFactory;
use HasFactory, HasDescription;

public $timestamps = false;

Expand All @@ -16,13 +17,4 @@ class AuthorContent extends Model
'lang',
'content'
];

public function getDescriptionAttribute()
{
$maxLength = config('blog.description_length');
if (strlen($this->content) > $maxLength)
$result = substr($this->content, 0, $maxLength);
else $result = $this->content;
return strip_tags(html_entity_decode($result));
}
}
8 changes: 2 additions & 6 deletions app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
namespace App\Models;

use App\Interfaces\Searchable;
use App\Traits\HasThumbnail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Category extends Model implements Searchable
{
use HasFactory;
use HasFactory, HasThumbnail;

public $timestamps = false;

protected $fillable = [
'thumbnail_path'
];

public function getThumbnailAttribute()
{
return asset('storage/thumbnails/'.$this->thumbnail_path);
}

public function posts()
{
return $this->belongsToMany(Post::class, 'posts_of_categories', 'category_id', 'post_id');
Expand Down
12 changes: 2 additions & 10 deletions app/Models/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@

namespace App\Models;

use App\Traits\HasDescription;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Content extends Model
{
use HasFactory;
use HasFactory, HasDescription;

protected $fillable = [
'lang',
'title',
'content',
'url'
];

public function getDescriptionAttribute()
{
$maxLength = config('blog.description_length');
if (strlen($this->content) > $maxLength)
$result = substr($this->content, 0, $maxLength);
else $result = $this->content;
return strip_tags(html_entity_decode($result));
}
}
8 changes: 2 additions & 6 deletions app/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace App\Models;

use App\Interfaces\Searchable;
use App\Traits\HasThumbnail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;

class Post extends Model implements Searchable, Feedable
{
use HasFactory;
use HasFactory, HasThumbnail;

public $timestamps = false;

Expand All @@ -36,11 +37,6 @@ public function relativePosts()
return collect([]);
}

public function getThumbnailAttribute()
{
return asset('storage/thumbnails/'.$this->thumbnail_path);
}

public function isVisible()
{
return $this->is_visible && empty($this->publish_at);
Expand Down
10 changes: 5 additions & 5 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use App\Interfaces\Searchable;
use App\Traits\HasThumbnail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
Expand All @@ -13,6 +14,10 @@ class User extends Authenticatable implements Searchable
{
use HasFactory, Notifiable, HasRoles, TwoFactorAuthenticatable;

use HasThumbnail {
getThumbnailAttribute as getAvatarAttribute;
}

/**
* The attributes that are mass assignable.
*
Expand Down Expand Up @@ -50,11 +55,6 @@ class User extends Authenticatable implements Searchable
'email_verified_at' => 'datetime',
];

public function getAvatarAttribute()
{
return asset('storage/thumbnails/'.$this->thumbnail_path);
}

public function getFullNameAttribute()
{
return $this->first_name.' '.$this->last_name;
Expand Down
15 changes: 15 additions & 0 deletions app/Traits/HasDescription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Traits;

trait HasDescription
{
public function getDescriptionAttribute()
{
$maxLength = config('blog.description_length');
if (strlen($this->content) > $maxLength)
$result = substr($this->content, 0, $maxLength);
else $result = $this->content;
return strip_tags(html_entity_decode($result));
}
}
11 changes: 11 additions & 0 deletions app/Traits/HasThumbnail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Traits;

trait HasThumbnail
{
public function getThumbnailAttribute()
{
return asset('storage/thumbnails/'.$this->thumbnail_path);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"laravel/framework": "^8.12",
"laravel/tinker": "^2.5",
"spatie/laravel-feed": "^2.7",
"stanfortonski/laravel-roles": "^2.1"
"stanfortonski/laravel-roles": "^3.1"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.5",
Expand Down
Loading

0 comments on commit e7bf459

Please sign in to comment.