mirror of
https://repo.getmonero.org/AnonDev/xmrmemes.git
synced 2025-08-18 19:18:26 -04:00
Initial Commit
This commit is contained in:
commit
cc2af611e1
148 changed files with 54234 additions and 0 deletions
58
app/Models/Meme.php
Normal file
58
app/Models/Meme.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Meme extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $appends = ['meme_tips_total'];
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
public function getMemeTipsTotalAttribute()
|
||||
{
|
||||
return $this->tips->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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue