1 | <?php namespace Arcanedev\LaravelTracker\Trackers; |
||
14 | class CookieTracker extends AbstractTracker implements CookieTrackerContract |
||
15 | { |
||
16 | /* ----------------------------------------------------------------- |
||
17 | | Getters and Setters |
||
18 | | ----------------------------------------------------------------- |
||
19 | */ |
||
20 | |||
21 | /** |
||
22 | * Get the model. |
||
23 | * |
||
24 | * @return \Arcanedev\LaravelTracker\Models\Cookie |
||
25 | */ |
||
26 | 3 | protected function getModel() |
|
30 | |||
31 | /* ----------------------------------------------------------------- |
||
32 | | Main Methods |
||
33 | | ----------------------------------------------------------------- |
||
34 | */ |
||
35 | |||
36 | /** |
||
37 | * Track the cookie. |
||
38 | * |
||
39 | * @param mixed $cookie |
||
40 | * |
||
41 | * @return int |
||
42 | */ |
||
43 | 3 | public function track($cookie) |
|
44 | { |
||
45 | 3 | if ( ! $cookie) { |
|
46 | $this->cookie()->queue( |
||
47 | $this->cookie()->make($this->getConfig('cookie.name'), $cookie = (string) Uuid::uuid4()) |
||
48 | ); |
||
49 | } |
||
50 | |||
51 | 3 | return $this->getModel() |
|
52 | 3 | ->newQuery() |
|
53 | 3 | ->firstOrCreate(['uuid' => $cookie]) |
|
54 | 3 | ->getKey(); |
|
55 | } |
||
56 | |||
57 | /* ----------------------------------------------------------------- |
||
58 | | Other Methods |
||
59 | | ----------------------------------------------------------------- |
||
60 | */ |
||
61 | |||
62 | /** |
||
63 | * Get the cookie instance. |
||
64 | * |
||
65 | * @return \Illuminate\Cookie\CookieJar |
||
66 | */ |
||
67 | private function cookie() |
||
71 | } |
||
72 |