done set database, model and seeder

original
ajikamaludin 2 years ago
parent 5c9bc57f84
commit df9ea70806
No known key found for this signature in database
GPG Key ID: E4F565A376B260B7

@ -8,4 +8,11 @@ use Illuminate\Database\Eloquent\Model;
class Department extends Model
{
use HasFactory;
protected $fillable = ['name'];
public function documents()
{
$this->hasMany(Document::class, 'document_id');
}
}

@ -0,0 +1,43 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Document extends Model
{
use HasFactory;
protected $fillable = [
'no',
'no_doc',
'type_doc_id',
'company_name',
'first_person_name',
'second_person_name',
'start_date',
'end_date',
'department_id',
'pic_name',
'email',
'note',
'document',
'user_id',
];
public function department()
{
return $this->belongsTo(Department::class, 'department_id');
}
public function type()
{
return $this->belongsTo(TypeDoc::class, 'type_doc_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'user_id');
}
}

@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class DocumentReminder extends Model
{
use HasFactory;
protected $fillable = [
'document_id',
'date',
];
public function document()
{
$this->belongsTo(Document::class, 'document_id');
}
}

@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class DocumentShare extends Model
{
use HasFactory;
protected $fillable = [
'document_id',
'user_id',
'share_to',
];
public function document()
{
$this->belongsTo(Document::class, 'document_id');
}
public function user()
{
$this->belongsTo(User::class, 'user_id');
}
}

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
use HasFactory;
}

@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class TypeDoc extends Model
{
use HasFactory;
protected $fillable = ['name'];
public function documents()
{
$this->hasMany(Document::class, 'document_id');
}
}

@ -14,6 +14,7 @@ return new class extends Migration {
{
Schema::create('departments', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('type_docs', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('type_docs');
}
};

@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('documents', function (Blueprint $table) {
$table->id();
$table->integer('no', false);
$table->string('no_doc');
$table->foreignId('type_doc_id')->constrained();
$table->string('company_name');
$table->string('first_person_name');
$table->string('second_person_name');
$table->dateTime('start_date');
$table->dateTime('end_date');
$table->foreignId('department_id')->constrained();
$table->string('pic_name');
$table->string('email');
$table->text('note');
$table->string('document');
$table->foreignId('user_id')->constrained();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('documents');
}
};

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('document_reminders', function (Blueprint $table) {
$table->id();
$table->foreignId('document_id')->constrained();
$table->dateTime('date');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('document_reminders');
}
};

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('document_shares', function (Blueprint $table) {
$table->id();
$table->foreignId('document_id')->constrained();
$table->foreignId('user_id')->nullable()->constrained();
$table->string('share_to')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('document_shares');
}
};

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->string('key');
$table->text('value');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('settings');
}
};

@ -3,6 +3,10 @@
namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\Department;
use App\Models\TypeDoc;
use App\Models\User;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
@ -14,20 +18,34 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// \App\Models\User::factory(10)->create();
\App\Models\User::factory()->create([
User::factory()->create([
'name' => 'Administrator',
'email' => 'admin@admin.com',
'password' => bcrypt('password'),
'is_admin' => 1, // admin user
]);
\App\Models\User::factory()->create([
User::factory()->create([
'name' => 'User',
'email' => 'user@admin.com',
'password' => bcrypt('password'),
'is_admin' => 0, // normal user
]);
if (Department::count() == 0) {
$departments = ['HRD', 'Purchasing', 'Finance, Accounting & Tax', 'Sales','HSE','Produksi','QA / QC','Maintenance'];
foreach ($departments as $dep) {
Department::create(['name' => $dep]);
}
}
if (TypeDoc::count() == 0) {
$types = ['Perijinan', 'Perjanjian Kerjasama', 'Kontrak Kerja'];
foreach ($types as $type) {
TypeDoc::create(['name' => $type]);
}
}
}
}

@ -140,7 +140,6 @@ export default function Authenticated({ auth, children }) {
<ToastContainer
position="top-right"
autoClose={5000}
theme="colored"
hideProgressBar={false}
newestOnTop={false}
closeOnClick

Loading…
Cancel
Save