Repository URL to install this package:
|
Version:
0.2.1 ▾
|
<?php namespace Modules\Students\Entities;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\Core\Utils\NameFormat;
use Pingpong\Modules\Exceptions\ModuleNotFoundException;
use Prettus\Repository\Contracts\Presentable;
use Prettus\Repository\Traits\PresentableTrait;
/**
* Modules\Students\Entities\Student
*
* @property integer $id
* @property string $first_name
* @property string $middle_name
* @property string $last_name
* @property string $profile_photo
* @property string $birthday
* @property string $country
* @property string $phone
* @property string $email
* @property boolean $is_active
* @property integer $users_id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $deleted_at
* @property-read \Modules\Users\Entities\User $user
* @property string $professional_doc
* @property-read \Illuminate\Database\Eloquent\Collection|\Modules\Courses\Entities\Analytic[] $analytic
* @property-read \Illuminate\Database\Eloquent\Collection|\Modules\Courses\Entities\Course[] $course
* @property-read \Illuminate\Database\Eloquent\Collection|\Modules\Exams\Entities\Exam[] $exam
* @property-read \Illuminate\Database\Eloquent\Collection|\Modules\Exams\Entities\Answer[] $answer
* @property-read mixed $full_name
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereId($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereFirstName($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereMiddleName($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereLastName($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereProfilePhoto($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereBirthday($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereCountry($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereProfessionalDoc($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student wherePhone($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereEmail($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereIsActive($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Modules\Students\Entities\Student whereDeletedAt($value)
* @mixin \Eloquent
*/
class Student extends Model implements Presentable {
use PresentableTrait,
SoftDeletes;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'students';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['first_name', 'middle_name', 'last_name', 'profile_photo', 'birthday', 'country', 'phone', 'email', 'professional_doc', 'is_active', 'users_id'];
protected $dates = ['birthday'];
/**
* Get the user for the student
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function user()
{
if (\Module::has('Users') == false) {
throw new ModuleNotFoundException();
}
return $this->hasOne('Modules\Users\Entities\User');
}
/**
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function analytic()
{
return $this->hasMany('Modules\Courses\Entities\Analytic', 'student_id');
}
/**
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function course()
{
return $this->belongsToMany('Modules\Courses\Entities\Course')->withPivot(['id']);
}
/**
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function exam()
{
return $this->belongsToMany('Modules\Exams\Entities\Exam')->withPivot(['id']);
}
/**
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function answer()
{
return $this->belongsToMany('Modules\Exams\Entities\Answer')->withPivot(['id', 'exam_id']);
}
public function getFullNameAttribute(){
return NameFormat::formatFullName($this->first_name, $this->middle_name[0].'.', $this->last_name);
}
}