mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-06 02:33:48 +00:00
52 lines
994 B
PHP
52 lines
994 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Share extends Model
|
|
{
|
|
use Notifiable, HasFactory;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $appends = ['link'];
|
|
|
|
public $incrementing = false;
|
|
|
|
protected $keyType = 'string';
|
|
|
|
protected $primaryKey = 'token';
|
|
|
|
/**
|
|
* Generate share link
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getLinkAttribute()
|
|
{
|
|
return url('/shared', ['token' => $this->attributes['token']]);
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->hasOne(User::class, 'id', 'user_id');
|
|
}
|
|
|
|
/**
|
|
* Model events
|
|
*/
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(function ($shared) {
|
|
$shared->id = (string)Str::uuid();
|
|
$shared->token = Str::random(16);
|
|
});
|
|
}
|
|
}
|