Skip to content

Commit c49517c

Browse files
authored
Merge pull request themsaid#42 from lucasmichot/feature/master/abstract-model
Create an abstract WinkModel.
2 parents 28e6239 + cdb70d3 commit c49517c

File tree

5 files changed

+22
-51
lines changed

5 files changed

+22
-51
lines changed

src/AbstractWinkModel.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Wink;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
abstract class AbstractWinkModel extends Model
8+
{
9+
/**
10+
* Get the current connection name for the model.
11+
*
12+
* @return string
13+
*/
14+
public function getConnectionName()
15+
{
16+
return config('wink.database_connection');
17+
}
18+
}

src/WinkAuthor.php

+1-12
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
namespace Wink;
44

5-
use Illuminate\Database\Eloquent\Model;
65
use Illuminate\Contracts\Auth\Authenticatable;
76

8-
class WinkAuthor extends Model implements Authenticatable
7+
class WinkAuthor extends AbstractWinkModel implements Authenticatable
98
{
109
/**
1110
* The attributes that aren't mass assignable.
@@ -143,14 +142,4 @@ public function getAvatarAttribute($value)
143142
{
144143
return $value ?: 'https://secure.gravatar.com/avatar/' . md5(strtolower(trim($this->email))) . '?s=80';
145144
}
146-
147-
/**
148-
* Get the current connection name for the model.
149-
*
150-
* @return string
151-
*/
152-
public function getConnectionName()
153-
{
154-
return config('wink.database_connection');
155-
}
156145
}

src/WinkPage.php

+1-13
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Wink;
44

5-
use Illuminate\Database\Eloquent\Model;
6-
7-
class WinkPage extends Model
5+
class WinkPage extends AbstractWinkModel
86
{
97
/**
108
* The attributes that aren't mass assignable.
@@ -51,14 +49,4 @@ class WinkPage extends Model
5149
'body' => 'string',
5250
'meta' => 'array',
5351
];
54-
55-
/**
56-
* Get the current connection name for the model.
57-
*
58-
* @return string
59-
*/
60-
public function getConnectionName()
61-
{
62-
return config('wink.database_connection');
63-
}
6452
}

src/WinkPost.php

+1-13
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Wink;
44

5-
use Illuminate\Database\Eloquent\Model;
6-
7-
class WinkPost extends Model
5+
class WinkPost extends AbstractWinkModel
86
{
97
/**
108
* The attributes that aren't mass assignable.
@@ -78,14 +76,4 @@ public function author()
7876
{
7977
return $this->belongsTo(WinkAuthor::class, 'author_id');
8078
}
81-
82-
/**
83-
* Get the current connection name for the model.
84-
*
85-
* @return string
86-
*/
87-
public function getConnectionName()
88-
{
89-
return config('wink.database_connection');
90-
}
9179
}

src/WinkTag.php

+1-13
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Wink;
44

5-
use Illuminate\Database\Eloquent\Model;
6-
7-
class WinkTag extends Model
5+
class WinkTag extends AbstractWinkModel
86
{
97
/**
108
* The attributes that aren't mass assignable.
@@ -60,16 +58,6 @@ public function posts()
6058
return $this->belongsToMany(WinkPost::class, 'wink_posts_tags', 'tag_id', 'post_id');
6159
}
6260

63-
/**
64-
* Get the current connection name for the model.
65-
*
66-
* @return string
67-
*/
68-
public function getConnectionName()
69-
{
70-
return config('wink.database_connection');
71-
}
72-
7361
/**
7462
* The "booting" method of the model.
7563
*

0 commit comments

Comments
 (0)