CrestRoad/laravel/app/Models/Paramedics.php

103 lines
3.5 KiB
PHP

<?php
namespace App\Models;
use Jenssegers\Mongodb\Eloquent\Model;
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
class Paramedics extends Model
{
use SoftDeletes;
protected $connection = 'mongodb';
protected $collection = 'Paramedics';
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $guarded = ['_id'];
protected $fillable = [ 'gender',
'city',
'date_of_birth',
'msl_code',
'language',
'completed_articles',
'type',
'createdAt',
'partition',
'is_deleted',
'user_info',
'article_count',
'highlight_qualification',
'context',
'state',
'id',
'email',
'updatedAt',
'is_active',
'hierarchy',
'hierarchy_info',
'is_verified',
'completed_article_count',
'clinic_institute_name',
'application',
'phone',
'user_id',
'domain',
'name',
'alternate_phone',
'type_of_setup',
'designation',
'position',
'status',
'context',
'parents',
'lms_completed_articles',
'lms_completed_quiz',
];
public function user()
{
return $this->belongsToMany(User::class);
}
public static function createnew($contact) {
$id = $contact->id;
unset($contact->id);
$contact = Paramedics::firstOrCreate(['id' => $id], (array)$contact);
return $contact;
}
public static function updateone($post, $user, $id) {
$contact = Contact::find($id);
foreach($post as $k => $p) {
if(isset($contact->{$k}) && $contact->{$k} != '' && $k != 'tags') unset($post[$k]);
}
$divisions = is_array($contact->divisions)?$contact->divisions:[];
$users = is_array($contact->users)?$contact->users:[];
$tags = is_array($contact->tags)?$contact->tags:[];
$divisions[] = $user->division_id;
$users[] = $user->id;
$tags = array_merge($tags, explode(',', $post['tags']));
$post['divisions'] = array_unique($divisions);
$post['users'] = array_unique($users);
$post['tags'] = array_unique($tags);
$contact->update($post);
return $contact;
}
public static function updatebyuser($post, $id) {
$contact = Contact::find($id);
foreach($post as $k => $p) {
if($p == '') unset($post[$k]);
}
$tags = is_array($contact['tags'])?$contact['tags']:[];
if(isset($post['tags'])) {
$tags = array_merge($tags, explode(',', $post['tags']));
}
unset($post['tags']);
$post['tags'] = array_unique($tags);
$contact->update($post);
return $contact;
}
}