-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paving the way for Metadata access via Eloquent.
Make the id the primary key on the filter_metadata table. Add unique constraint to disk, path columns. Add BackingData cast for filer_metadata->backing_data DB column. Update the Database repository to format the timestamp correctly. Add Uuid trait to support creation of Metadata through the Eloquent model. Update the base TestCase to support config changes.
- Loading branch information
Showing
6 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Nvahalik\Filer\Casts; | ||
|
||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
|
||
class BackingData implements CastsAttributes | ||
{ | ||
|
||
public function get($model, string $key, $value, array $attributes) | ||
{ | ||
return \Nvahalik\Filer\BackingData::unserialize($value); | ||
} | ||
|
||
public function set($model, string $key, $value, array $attributes) | ||
{ | ||
return $value->toJson(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Nvahalik\Filer\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Nvahalik\Filer\Casts\BackingData; | ||
use Nvahalik\Filer\Traits\Uuid; | ||
|
||
class Metadata extends Model | ||
{ | ||
use Uuid; | ||
|
||
protected $table = 'filer_metadata'; | ||
|
||
/** | ||
* Indicates if the IDs are auto-incrementing. | ||
* | ||
* @var bool | ||
*/ | ||
public $incrementing = false; | ||
|
||
/** | ||
* The "type" of the auto-incrementing ID. | ||
* | ||
* @var string | ||
*/ | ||
protected $keyType = 'uuid'; | ||
|
||
protected $fillable = [ | ||
'id', | ||
'disk', | ||
'path', | ||
'size', | ||
'mimetype', | ||
'etag', | ||
'visibility', | ||
'backing_data', | ||
'timestamp', | ||
]; | ||
|
||
protected $casts = [ | ||
'size' => 'integer', | ||
'backing_data' => BackingData::class | ||
]; | ||
|
||
protected $dates = [ | ||
'timestamp', | ||
]; | ||
|
||
public function __construct(array $attributes = []) | ||
{ | ||
parent::__construct($attributes); | ||
|
||
$this->setConnection(config('filer.database.connection')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Nvahalik\Filer\Traits; | ||
|
||
use Illuminate\Support\Str; | ||
|
||
trait Uuid | ||
{ | ||
protected static function boot() | ||
{ | ||
parent::boot(); | ||
|
||
static::creating(function ($model) { | ||
$model->id = (string) Str::uuid(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters