first commit
This commit is contained in:
26
app/Models/Answer.php
Normal file
26
app/Models/Answer.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Answer extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'response_id',
|
||||
'question_id',
|
||||
'option_id',
|
||||
'answer_text',
|
||||
];
|
||||
|
||||
public function response()
|
||||
{
|
||||
return $this->belongsTo(Response::class);
|
||||
}
|
||||
|
||||
public function question()
|
||||
{
|
||||
return $this->belongsTo(Question::class);
|
||||
}
|
||||
|
||||
}
|
||||
14
app/Models/Option.php
Normal file
14
app/Models/Option.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Option extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'question_id',
|
||||
'option_text',
|
||||
];
|
||||
|
||||
}
|
||||
33
app/Models/Question.php
Normal file
33
app/Models/Question.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Question extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'section_id',
|
||||
'question_text',
|
||||
'type',
|
||||
'allow_other_option',
|
||||
'order',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'lain_lain' => 'boolean',
|
||||
];
|
||||
|
||||
public function section()
|
||||
{
|
||||
return $this->belongsTo(Section::class);
|
||||
}
|
||||
public function options()
|
||||
{
|
||||
return $this->hasMany(Option::class);
|
||||
}
|
||||
public function answers()
|
||||
{
|
||||
return $this->hasMany(Answer::class);
|
||||
}
|
||||
}
|
||||
30
app/Models/Response.php
Normal file
30
app/Models/Response.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Response extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'survey_id',
|
||||
'user_id',
|
||||
'respondent_name',
|
||||
'respondent_no_pekerja',
|
||||
'respondent_jabatan',
|
||||
];
|
||||
|
||||
|
||||
public function survey()
|
||||
{
|
||||
return $this->belongsTo(Survey::class);
|
||||
}
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
} // Responden
|
||||
public function answers()
|
||||
{
|
||||
return $this->hasMany(Answer::class);
|
||||
}
|
||||
}
|
||||
18
app/Models/Section.php
Normal file
18
app/Models/Section.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Section extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'survey_id',
|
||||
'title',
|
||||
'description',
|
||||
'order',
|
||||
];
|
||||
|
||||
public function survey() { return $this->belongsTo(Survey::class); }
|
||||
public function questions() { return $this->hasMany(Question::class); }
|
||||
}
|
||||
32
app/Models/Survey.php
Normal file
32
app/Models/Survey.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Survey extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'date',
|
||||
'user_id',
|
||||
'uuid',
|
||||
'perincian',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
if (empty($model->uuid)) {
|
||||
$model->uuid = (string) \Illuminate\Support\Str::uuid();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function user() { return $this->belongsTo(User::class); }
|
||||
public function sections() { return $this->hasMany(Section::class); }
|
||||
public function questions() { return $this->hasManyThrough(Question::class, Section::class); }
|
||||
public function responses() { return $this->hasMany(Response::class); }
|
||||
}
|
||||
71
app/Models/User.php
Normal file
71
app/Models/User.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'password',
|
||||
'role',
|
||||
'no_pekerja',
|
||||
'jabatan',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
// Helper: isAdmin
|
||||
public function isAdmin(): bool {
|
||||
return $this->role === 'admin';
|
||||
}
|
||||
|
||||
// Helper: isStaff
|
||||
public function isStaff(): bool {
|
||||
return $this->role === 'staff';
|
||||
}
|
||||
|
||||
public function scopeSearch($query, $keyword)
|
||||
{
|
||||
return $query->where('name', 'like', "%$keyword%")
|
||||
->orWhere('no_pekerja', 'like', "%$keyword%")
|
||||
->orWhere('jabatan', 'like', "%$keyword%");
|
||||
}
|
||||
|
||||
public function surveys() { return $this->hasMany(Survey::class); }
|
||||
public function responses() { return $this->hasMany(Response::class); }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user