-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBase.php
More file actions
70 lines (58 loc) · 1.47 KB
/
Copy pathBase.php
File metadata and controls
70 lines (58 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php namespace Feather\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Base extends Eloquent {
/**
* The default connection used by Feather.
*
* @var string
*/
public $connection = FEATHER_DATABASE;
/**
* Cache time in minutes.
*
* @var int
*/
const cache_time = 720;
/**
* Array of cachable items and the appropriate foreign keys.
*
* @var array
*/
public static $cachable = array(
'place' => array('place', 'place_id'),
'user' => array('user', 'user_id'),
'author' => array('user', 'user_id')
);
/**
* Get a new query builder for the model's table.
*
* @return Feather\Models\Builder
*/
public function newQuery()
{
$builder = new Builder($this->newBaseQueryBuilder());
// Once we have the query builders, we will set the model instances so the
// builder can easily access any information it may need from the model
// while it is constructing and executing various queries against it.
$builder->setModel($this);
return $builder;
}
/**
* Handle the dynamic retrieval of attributes and associations.
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
if (isset(static::$cachable[$key]) and ! isset($this->attributes[$key]) and ! isset($this->relations[$key]))
{
list($group, $foreign) = static::$cachable[$key];
if (Cache::has("{$group}_{$this->$foreign}"))
{
return Cache::get("{$group}_{$this->$foreign}");
}
}
return parent::__get($key);
}
}