mirror of
https://repo.getmonero.org/AnonDev/xmrmemes.git
synced 2024-12-22 06:05:02 -05:00
dbfda5cf9e
Add dark / light theme Add social sharing on meme pages Add approving / pending admin section Improve design Add pagination on profiles Make front end date time user friendly Finish rough draft of site And Much more... Still need to fix a few minor things before it goes live. Almost complete.
68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Meme extends Model
|
|
{
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
|
|
protected $guarded = ['id'];
|
|
protected $appends = ['meme_tips_total'];
|
|
|
|
protected static function booted()
|
|
{
|
|
static::addGlobalScope('approved', function (Builder $builder) {
|
|
$builder->where('is_approved', 1);
|
|
});
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function address()
|
|
{
|
|
return $this->belongsTo(Address::class);
|
|
}
|
|
|
|
public function tips()
|
|
{
|
|
return $this->hasManyThrough(Tip::class, Address::class, 'id', 'address_id', 'address_id', 'id')->orderBy('created_at', 'DESC');
|
|
}
|
|
|
|
public function getMemeTipsTotalAttribute()
|
|
{
|
|
return $this->tips->where('is_deposit', 1)->sum('amount_formatted');
|
|
}
|
|
|
|
public function setImageAttribute($value)
|
|
{
|
|
$attribute_name = "image";
|
|
$disk = "uploads";
|
|
$destination_path = "uploads/memes";
|
|
$image = \Image::make($value)->encode($value->extension(), 90);
|
|
$fix_rotation_issues = $image->orientate();
|
|
$filename = md5($value.time()) . '.' . $value->extension();
|
|
|
|
if ($value->extension() == 'gif') {
|
|
// Work around to get GIFs to work
|
|
copy($value->getRealPath(), $destination_path.'/'.$filename);
|
|
$image->destroy();
|
|
}
|
|
else {
|
|
\Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
|
|
}
|
|
|
|
$this->attributes[$attribute_name] = $destination_path.'/'.$filename;
|
|
}
|
|
|
|
}
|