Issues (19)

src/Models/Traits/ProjectLocationTrait.php (1 issue)

1
<?php
2
3
namespace Sfneal\Models\Traits;
4
5
trait ProjectLocationTrait
6
{
7
    /**
8
     * Retrieve a string with the Article's project city, project state.
9
     *
10
     * @return string|null
11
     */
12
    public function getProjectLocationAttribute()
13
    {
14
        if (isset($this->project_city) && isset($this->project_state)) {
15
            return "{$this->project_city}, {$this->project_state}";
16
        } else {
17
            return null;
18
        }
19
    }
20
21
    /**
22
     * Parse project_location attribute into city and state values.
23
     *
24
     * @param  $value
25
     */
26
    public function setProjectLocationAttribute($value)
27
    {
28
        if (isset($value)) {
29
            $city_state = explode(', ', $value);
30
            $this->attributes['project_city'] = $city_state[0];
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
            $this->attributes['project_state'] = $city_state[1];
32
        }
33
    }
34
}
35