Place   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getIdByTitle() 0 15 3
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use LaravelEnso\Tables\Traits\TableCache;
7
8
class Place extends Model
9
{
10
    use TableCache;
11
    // public function __construct(Array $attributes = [])
12
    // {
13
    //     parent::__construct($attributes);
14
    //     $db = \Session::get('db');
15
    //     error_log('+++++++++++++++++++++++++++++++++++'.$db);
16
    //     if(empty($db)) {
17
    //         $db = env('DB_DATABASE', 'enso');
18
    //     }
19
    //     if($db === env('DB_DATABASE')) {
20
    //         $key = 'database.connections.mysql.database';
21
    //         config([$key => $db]);
22
    //     } else {
23
    //         $key = 'database.connections.mysql.database';
24
    //         config([$key => $db]);
25
    //     }
26
    //     \DB::purge('mysql');
27
    //     \DB::reconnect('mysql');
28
    //     $this->setConnection('mysql');
29
    //     error_log('-----------------------------------'.$this->getConnection()->getDatabaseName());
30
    // }
31
    protected $fillable = ['description', 'title', 'date'];
32
33
    public static function getIdByTitle($title)
34
    {
35
        $id = null;
36
        if (empty($title)) {
37
            return $id;
38
        }
39
        $place = self::where('title', $title)->first();
40
        if ($place !== null) {
41
            $id = $place->id;
42
        } else {
43
            $place = self::create(compact('title'));
44
            $id = $place->id;
45
        }
46
47
        return $id;
48
    }
49
}
50