HEX
Server: LiteSpeed
System: Linux s1296.sgp1.mysecurecloudhost.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: bishwesh (1878)
PHP: 7.4.33
Disabled: NONE
Upload Files
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));
    }
}