Implement file upload and viewing functionality; refactor letter migrations and models to use UUIDs
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class FileUpload extends Model
|
||||
{
|
||||
use HasFactory, HasUuids;
|
||||
|
||||
protected $table = 'file_uploads';
|
||||
protected $keyType = 'string';
|
||||
public $incrementing = false;
|
||||
|
||||
protected $fillable = ['letter_id', 'file_name', 'file_path', 'mime_type'];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
static::creating(function ($model) {
|
||||
$model->id = Str::uuid()->toString();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Letter extends Model
|
||||
{
|
||||
use HasFactory, HasUuids;
|
||||
|
||||
protected $table = 'letters';
|
||||
protected $keyType = 'string';
|
||||
public $incrementing = false;
|
||||
|
||||
protected $fillable = [
|
||||
'nama_mahasiswa',
|
||||
'nomor_induk_mahasiswa',
|
||||
'program_studi_mahasiswa',
|
||||
'tahun_ajaran',
|
||||
'start_date',
|
||||
'completion_date',
|
||||
'lampiran',
|
||||
'is_acceptance',
|
||||
'nomor_surat_acceptance',
|
||||
'is_completion',
|
||||
'nomor_surat_completion',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
static::creating(function ($model) {
|
||||
$model->id = Str::uuid()->toString();
|
||||
});
|
||||
}
|
||||
|
||||
public function fileUpload()
|
||||
{
|
||||
return $this->hasOne(FileUpload::class, 'letter_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
@@ -46,4 +47,15 @@ class User extends Authenticatable
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
protected $keyType = 'string';
|
||||
public $incrementing = false;
|
||||
|
||||
public static function boot() {
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
$model->id = Str::uuid();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user