File: /home/bishwesh/internstolearn.com/app/Models/Internship.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class Internship extends Model
{
//table for model
// TODO: correct table name
protected $table = 'interships';
protected $primaryKey = 'id';
// define fields which can be mass assigned
protected $fillable = [
'title',
'category_id',
'qualification_id',
'intern_ship_type_id',
'user_id',
'description',
'address',
'featured_image',
'deadline',
'salary_package',
'checked',
'view_count',
'featured'
];
protected $casts = [
'created_at' => 'datetime:Y-m-d',
'deadline' => 'date:Y-m-d',
];
/**
* Maintains one to one relation with company
* Each intern is posted by company
*/
public function company()
{
return $this->hasOne('App\Models\Company', 'id', 'user_id');
}
public function companyName()
{
return $this->hasOne('App\User', 'id', 'user_id');
}
/**
* One to one relation with category
*/
public function category()
{
return $this->hasOne('App\Models\Category', 'id', 'category_id');
}
// RelationShip with tags
public function tags()
{
return $this->morphToMany('App\Models\Tag', 'taggable');
}
public function applicants()
{
return $this->belongsToMany('App\User', 'internship_user', 'internship_id', 'user_id')->withPivot('status');
}
public function path()
{
return url("/internships/{$this->id}-" . Str::slug($this->title));
}
}