Examination_student::insertData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\DB;
7
8
class Examination_student extends Model
9
{
10
11
12
    /**
13
     * The database table used by the model.
14
     *
15
     * @var string
16
     */
17
    protected $table = 'examination_students';
18
19
    /**
20
     * Attributes that should be mass-assignable.
21
     *
22
     * @var array
23
     */
24
    protected $fillable = ['st_no', 'stu_no', 'nsid', 'school_id', 'full_name', 'dob', 'gender', 'address', 'annual_income', 'has_special_need', 'disable_type', 'disable_details', 'special_education_centre'];
25
26
    /**
27
     * The attributes excluded from the model's JSON form.
28
     *
29
     * @var array
30
     */
31
    protected $hidden = [];
32
33
    /**
34
     * The attributes that should be casted to native types.
35
     *
36
     * @var array
37
     */
38
    protected $casts = ['has_special_need' => 'boolean'];
39
40
    /**
41
     * The attributes that should be mutated to dates.
42
     *
43
     * @var array
44
     */
45
    protected $dates = ['dob'];
46
47
    protected $primaryKey = 'st_no';
48
49
    public $timestamps = true;
50
51
    public static function insertData($data)
52
    {
53
        $output = new \Symfony\Component\Console\Output\ConsoleOutput();
54
        $value = self::where('st_no', $data['st_no'])->get();
55
        if (count($value) > 0) {
56
            self::where('st_no', $data['st_no'])->update($data);
57
        } else {
58
            self::insert($data);
59
        }
60
        $output->writeln('Student name: ' . ($data['f_name']) . ' has been inserted to the database');
61
    }
62
}
63