Skip to content

Commit 437315a

Browse files
Misc updates
+ Fixing Traits & Tests + Adding PHP 7.2 support + Updating the docs
1 parent c504433 commit 437315a

18 files changed

+82
-158
lines changed

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ checks:
2323
tools:
2424
external_code_coverage:
2525
timeout: 600
26-
runs: 2
26+
runs: 3
2727
php_code_sniffer:
2828
enabled: true
2929
config:

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sudo: false
55
php:
66
- 7.0
77
- 7.1
8+
- 7.2
89
- nightly
910

1011
matrix:

_docs/3.Usage.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Post extends Model {
6464
}
6565
}
6666
```
67-
67+
6868
#### Getting Notes
6969

7070
```php
@@ -73,7 +73,19 @@ $notes = $post->notes;
7373
```
7474

7575
> **NOTE :** `$post->notes` relation property is only available in the `HasManyNotes` trait. If you're using `HasOneNote` trait, use `$post->note` instead.
76+
77+
#### Getting the author's notes
7678

79+
You can also retrieve all the author's notes by using the `Arcanedev\LaravelNotes\Traits\AuthoredNotes` Trait in your User model (for example).
80+
81+
```php
82+
$user = App\User::first();
83+
$post = App\Post::first();
84+
$post->createNote('Hello world #1', $user);
85+
86+
$notes = $user->authoredNotes;
87+
```
88+
7789
#### Finding a note with a specific ID
7890

7991
```php

database/migrations/2016_10_00_000001_create_notes_table.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ public function __construct()
2424
{
2525
parent::__construct();
2626

27-
$this->setTable(
28-
$this->getTableFromConfig('notes', 'notes')
29-
);
27+
$this->setTable(config('notes.notes.table', 'notes'));
3028
}
3129

3230
/* -----------------------------------------------------------------
@@ -43,13 +41,13 @@ public function up()
4341
$table->increments('id');
4442
$table->text('content');
4543
$table->morphs('noteable');
46-
$table->integer('author_id', false, true)->nullable();
44+
$table->unsignedInteger('author_id')->nullable();
4745
$table->timestamps();
4846

4947
$table->foreign('author_id')
50-
->references('id')
51-
->on($this->getTableFromConfig('authors', 'users'))
52-
->onDelete('cascade');
48+
->references('id')
49+
->on(config('notes.authors.table', 'users'))
50+
->onDelete('cascade');
5351
});
5452
}
5553
}

src/Bases/Migration.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php namespace Arcanedev\LaravelNotes\Bases;
22

3-
use Arcanedev\LaravelNotes\Traits\ConfigHelper;
4-
use Arcanedev\Support\Bases\Migration as BaseMigration;
3+
use Arcanedev\Support\Database\Migration as BaseMigration;
54

65
/**
76
* Class Migration
@@ -11,13 +10,6 @@
1110
*/
1211
abstract class Migration extends BaseMigration
1312
{
14-
/* -----------------------------------------------------------------
15-
| Traits
16-
| -----------------------------------------------------------------
17-
*/
18-
19-
use ConfigHelper;
20-
2113
/* -----------------------------------------------------------------
2214
| Constructor
2315
| -----------------------------------------------------------------
@@ -28,7 +20,7 @@ abstract class Migration extends BaseMigration
2820
*/
2921
public function __construct()
3022
{
31-
$this->setConnection($this->getFromConfig('database.connection'));
32-
$this->setPrefix($this->getFromConfig('database.prefix'));
23+
$this->setConnection(config('notes.database.connection'));
24+
$this->setPrefix(config('notes.database.prefix'));
3325
}
3426
}

src/Models/AbstractModel.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
<?php namespace Arcanedev\LaravelNotes\Models;
22

3-
use Arcanedev\LaravelNotes\Traits\ConfigHelper;
4-
use Arcanedev\Support\Bases\Model as BaseModel;
3+
use Arcanedev\Support\Database\Model;
54

65
/**
76
* Class AbstractModel
87
*
98
* @package Arcanedev\LaravelMessenger\Bases
109
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
1110
*/
12-
abstract class AbstractModel extends BaseModel
11+
abstract class AbstractModel extends Model
1312
{
14-
/* -----------------------------------------------------------------
15-
| Traits
16-
| -----------------------------------------------------------------
17-
*/
18-
19-
use ConfigHelper;
20-
2113
/* -----------------------------------------------------------------
2214
| Constructor
2315
| -----------------------------------------------------------------
@@ -32,7 +24,7 @@ public function __construct(array $attributes = [])
3224
{
3325
parent::__construct($attributes);
3426

35-
$this->setConnection($this->getFromConfig('database.connection'));
36-
$this->setPrefix($this->getFromConfig('database.prefix'));
27+
$this->setConnection(config('notes.database.connection'));
28+
$this->setPrefix(config('notes.database.prefix'));
3729
}
3830
}

src/Models/Note.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct(array $attributes = [])
6363
{
6464
parent::__construct($attributes);
6565

66-
$this->setTable($this->getTableFromConfig('notes', 'notes'));
66+
$this->setTable(config('notes.notes.table', 'notes'));
6767
}
6868

6969
/* -----------------------------------------------------------------
@@ -88,6 +88,6 @@ public function noteable()
8888
*/
8989
public function author()
9090
{
91-
return $this->belongsTo($this->getModelFromConfig('authors'));
91+
return $this->belongsTo(config('notes.authors.model'));
9292
}
9393
}

src/Traits/AuthoredNotes.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
namespace Arcanedev\LaravelNotes\Traits;
1+
<?php namespace Arcanedev\LaravelNotes\Traits;
42

53
use Arcanedev\LaravelNotes\Models\Note;
64

@@ -9,6 +7,8 @@
97
*
108
* @package Arcanedev\LaravelNotes\Traits
119
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
10+
*
11+
* @property \Illuminate\Database\Eloquent\Collection authoredNotes
1212
*/
1313
trait AuthoredNotes
1414
{
@@ -20,11 +20,10 @@ trait AuthoredNotes
2020
/**
2121
* Relation to ONE note.
2222
*
23-
* @return \Illuminate\Database\Eloquent\Relations\MorphOne
23+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
2424
*/
2525
public function authoredNotes()
2626
{
2727
return $this->hasMany(config('notes.notes.model', Note::class), 'author_id');
2828
}
29-
3029
}

src/Traits/ConfigHelper.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/Traits/HasManyNotes.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
*/
1515
trait HasManyNotes
1616
{
17-
/* -----------------------------------------------------------------
18-
| Traits
19-
| -----------------------------------------------------------------
20-
*/
21-
22-
use ConfigHelper;
23-
2417
/* -----------------------------------------------------------------
2518
| Relationships
2619
| -----------------------------------------------------------------
@@ -33,7 +26,7 @@ trait HasManyNotes
3326
*/
3427
public function notes()
3528
{
36-
return $this->morphMany($this->getModelFromConfig('notes'), 'noteable');
29+
return $this->morphMany(config('notes.notes.model'), 'noteable');
3730
}
3831

3932
/* -----------------------------------------------------------------
@@ -57,7 +50,9 @@ public function createNote($content, $author = null, $reload = true)
5750
$this->prepareNoteAttributes($content, $author)
5851
);
5952

60-
if ($reload) $this->load(['notes']);
53+
$relations = array_merge(['notes'], method_exists($this, 'authoredNotes') ? ['authoredNotes'] : []);
54+
55+
if ($reload) $this->load($relations);
6156

6257
return $note;
6358
}

0 commit comments

Comments
 (0)