Skip to content

Commit 0dab9e8

Browse files
committed
edit Traits
1 parent 9931215 commit 0dab9e8

File tree

10 files changed

+76
-66
lines changed

10 files changed

+76
-66
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,23 @@ in composer.php file:
3434
```
3535

3636
#### Helper Traits
37+
3738
``Miladimos\Toolkit\Traits\RouteKeyNameUUID``
39+
3840
``Miladimos\Toolkit\Traits\HasUUID``
41+
3942
``Miladimos\Toolkit\Traits\HasTimestamps``
43+
4044
``Miladimos\Toolkit\Traits\HasTags``
45+
4146
``Miladimos\Toolkit\Traits\HasJWT``
47+
4248
``Miladimos\Toolkit\Traits\HasAuthor``
49+
4350
``Miladimos\Toolkit\Traits\HasComment``
51+
4452
``Miladimos\Toolkit\Traits\GetConstantsEnum``
53+
4554
``Miladimos\Toolkit\Traits\ApiResponder``
4655

4756

databases/migrations/create_ir_banks_table.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CreateIrBanksTable extends Migration
1414
$table->uuid('uuid')->index();
1515
$table->string('title')->unique();
1616
$table->string('slug')->unique();
17-
$table->text('icon')->nullable();
17+
$table->text('logo')->nullable();
1818
$table->char('type')->nullable();
1919
$table->softDeletes();
2020
$table->timestamps();

databases/seeds/IrBankSeeder.php

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@ class IrBankSeeder extends Seeder
1111
public function run()
1212
{
1313
$banks = array(
14-
array('id' => '1', 'title' => 'صادرات', 'type'=> 'دولتی'),
15-
array('id' => '2', 'title' => 'ملّی ایران', 'type'=> 'دولتی'),
16-
array('id' => '3', 'title' => 'مسکن', 'type'=> 'دولتی'),
17-
array('id' => '4', 'title' => 'آینده', 'type'=> 'دولتی'),
18-
array('id' => '5', 'title' => 'پارسیان', 'type'=> 'دولتی'),
19-
array('id' => '6', 'title' => 'شهر', 'type'=> 'دولتی'),
20-
array('id' => '7', 'title' => 'اقتصاد نوین', 'type'=> 'دولتی'),
21-
array('id' => '8', 'title' => 'تات', 'type'=> 'دولتی'),
22-
array('id' => '9', 'title' => 'سپه', 'type'=> 'دولتی'),
23-
array('id' => '10', 'title' => 'صنعت و معدن', 'type'=> 'دولتی'),
24-
array('id' => '11', 'title' => 'توسعه صادرات ایران', 'type'=> 'دولتی'),
25-
array('id' => '12', 'title' => 'توسعه تعاون', 'type'=> 'دولتی'),
26-
array('id' => '13', 'title' => 'پست بانک ایران', 'type'=> 'دولتی'),
27-
array('id' => '14', 'title' => 'کارآفرین', 'type'=> 'دولتی'),
28-
array('id' => '15', 'title' => 'سامان', 'type'=> 'دولتی'),
29-
array('id' => '16', 'title' => 'سینا', 'type'=> 'دولتی'),
30-
array('id' => '17', 'title' => 'خاور میانه', 'type'=> 'دولتی'),
31-
array('id' => '18', 'title' => 'دی', 'type'=> 'دولتی'),
32-
array('id' => '20', 'title' => 'ملت', 'type'=> 'دولتی'),
33-
array('id' => '21', 'title' => 'تجارت', 'type'=> 'دولتی'),
34-
array('id' => '22', 'title' => 'رفاه', 'type'=> 'دولتی'),
35-
array('id' => '23', 'title' => ' حکمت ایرانیان', 'type'=> 'دولتی'),
36-
array('id' => '24', 'title' => 'گردشگری', 'type'=> 'دولتی'),
37-
array('id' => '25', 'title' => 'ایران زمین', 'type'=> 'دولتی'),
38-
array('id' => '26', 'title' => 'قوامین', 'type'=> 'دولتی'),
39-
array('id' => '27', 'title' => 'انصار', 'type'=> 'دولتی'),
40-
array('id' => '28', 'title' => 'سرمایه', 'type'=> 'دولتی'),
41-
array('id' => '29', 'title' => 'پاسارگاد', 'type'=> 'دولتی'),
42-
array('id' => '30', 'title' => 'بانک قرض‌الحسنه مهر ایران', 'type'=> 'دولتی'),
43-
array('id' => '31', 'title' => 'بانک قرض‌الحسنه رسالت', 'type'=> 'دولتی'),
44-
array('id' => '32', 'title' => 'دیگر', 'type'=> 'دولتی'),
14+
array('id' => '1', 'title' => 'صادرات', 'type'=> 'دولتی', 'logo' => ''),
15+
array('id' => '2', 'title' => 'ملّی ایران', 'type'=> 'دولتی', 'logo' => ''),
16+
array('id' => '3', 'title' => 'مسکن', 'type'=> 'دولتی', 'logo' => ''),
17+
array('id' => '4', 'title' => 'آینده', 'type'=> 'خصوصی', 'logo' => ''),
18+
array('id' => '5', 'title' => 'پارسیان', 'type'=> 'دولتی', 'logo' => ''),
19+
array('id' => '6', 'title' => 'شهر', 'type'=> 'دولتی', 'logo' => ''),
20+
array('id' => '7', 'title' => 'اقتصاد نوین', 'type'=> 'دولتی', 'logo' => ''),
21+
array('id' => '8', 'title' => 'تات', 'type'=> 'دولتی', 'logo' => ''),
22+
array('id' => '9', 'title' => 'سپه', 'type'=> 'دولتی', 'logo' => ''),
23+
array('id' => '10', 'title' => 'صنعت و معدن', 'type'=> 'دولتی', 'logo' => ''),
24+
array('id' => '11', 'title' => 'توسعه صادرات ایران', 'type'=> 'دولتی', 'logo' => ''),
25+
array('id' => '12', 'title' => 'توسعه تعاون', 'type'=> 'دولتی', 'logo' => ''),
26+
array('id' => '13', 'title' => 'پست بانک ایران', 'type'=> 'دولتی', 'logo' => ''),
27+
array('id' => '14', 'title' => 'کارآفرین', 'type'=> 'دولتی', 'logo' => ''),
28+
array('id' => '15', 'title' => 'سامان', 'type'=> 'دولتی', 'logo' => ''),
29+
array('id' => '16', 'title' => 'سینا', 'type'=> 'دولتی', 'logo' => ''),
30+
array('id' => '17', 'title' => 'خاور میانه', 'type'=> 'دولتی', 'logo' => ''),
31+
array('id' => '18', 'title' => 'دی', 'type'=> 'دولتی', 'logo' => ''),
32+
array('id' => '20', 'title' => 'ملت', 'type'=> 'دولتی', 'logo' => ''),
33+
array('id' => '21', 'title' => 'تجارت', 'type'=> 'دولتی', 'logo' => ''),
34+
array('id' => '22', 'title' => 'رفاه', 'type'=> 'دولتی', 'logo' => ''),
35+
array('id' => '23', 'title' => ' حکمت ایرانیان', 'type'=> 'دولتی', 'logo' => ''),
36+
array('id' => '24', 'title' => 'گردشگری', 'type'=> 'دولتی', 'logo' => ''),
37+
array('id' => '25', 'title' => 'ایران زمین', 'type'=> 'دولتی', 'logo' => ''),
38+
array('id' => '26', 'title' => 'قوامین', 'type'=> 'دولتی', 'logo' => ''),
39+
array('id' => '27', 'title' => 'انصار', 'type'=> 'دولتی', 'logo' => ''),
40+
array('id' => '28', 'title' => 'سرمایه', 'type'=> 'دولتی', 'logo' => ''),
41+
array('id' => '29', 'title' => 'پاسارگاد', 'type'=> 'دولتی', 'logo' => ''),
42+
array('id' => '30', 'title' => 'بانک قرض‌الحسنه مهر ایران', 'type'=> 'دولتی', 'logo' => ''),
43+
array('id' => '31', 'title' => 'بانک قرض‌الحسنه رسالت', 'type'=> 'دولتی', 'logo' => ''),
44+
array('id' => '32', 'title' => 'دیگر', 'type'=> 'دولتی', 'logo' => ''),
4545
);
4646

4747

@@ -50,6 +50,7 @@ public function run()
5050
IrBank::create([
5151
'id' => $data['id'],
5252
'title' => $data['title'],
53+
'logo' => $data['logo'],
5354
]);
5455
}
5556
}

src/Models/IrBank.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ class IrBank extends Model
1919

2020
protected $guarded = [];
2121

22-
23-
public function getRouteKeyName()
24-
{
25-
return 'uuid';
26-
}
27-
2822
public function sluggable(): array
2923
{
3024
return [

src/Providers/ToolkitServiceProvider.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,4 @@ public function publishStubs()
5656
__DIR__ . '/../Console/Stubs' => resource_path('vendor/miladimos/toolkit/stubs'),
5757
], 'toolkit-stubs');
5858
}
59-
60-
// protected function registerPublishes()
61-
// {
62-
// $helperFile = config('toolkit.file');
63-
// $this->publishes([
64-
// __DIR__ . '/Toolkit/toolkit.php' => app_path("Toolkit/$helperFile.php"),
65-
// ], 'toolkit-file');
66-
// }
67-
68-
// public function registerToolkit()
69-
// {
70-
// // Load the helpers in app/Http/helpers.php
71-
// if (file_exists($file = app_path('Http/helpers.php')))
72-
// {
73-
// require $file;
74-
// }
75-
// }
7659
}

src/Traits/HasAuthor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait HasAuthor
99
{
1010
public function author()
1111
{
12-
return $this->authorRelation;
12+
return $this->authorRelation();
1313
}
1414

1515
public function authorRelation(): BelongsTo

src/Traits/HasComment.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait HasComment
99
{
1010
public function comments()
1111
{
12-
return $this->commentsRelation;
12+
return $this->commentsRelation();
1313
}
1414

1515
public function commentsRelation(): MorphMany
@@ -20,11 +20,15 @@ public function commentsRelation(): MorphMany
2020
public function syncComments(array $comments)
2121
{
2222
$this->commentsRelation()->sync($comments);
23-
$this->save();
2423
}
2524

26-
public function removeComments()
25+
public function removeComments(array $comments)
2726
{
28-
$this->commentsRelation()->detach();
27+
$this->commentsRelation()->detach($comments);
28+
}
29+
30+
public function commentCount(): int
31+
{
32+
return $this->comments()->count();
2933
}
3034
}

src/Traits/HasLikes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
trait HasLikes
1010
{
11-
//
1211
protected static function bootHasLikes()
1312
{
1413
static::deleting(function ($model) {

src/Traits/HasTags.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@ trait HasTags
99
{
1010
public function tags()
1111
{
12-
return $this->tagsRelation;
12+
return $this->tagsRelation();
1313
}
1414

1515
public function tagsRelation(): MorphToMany
1616
{
17-
return $this->morphToMany(Tag::class, 'taggable', 'taggables')->withTimestamps();
17+
return $this->morphToMany(Tag::class, 'taggable', 'taggables');
1818
}
1919

2020
public function syncTags(array $tags)
2121
{
22-
$this->save();
2322
$this->tagsRelation()->sync($tags);
2423
}
2524

26-
public function removeTags()
25+
public function removeTags(array $tags)
2726
{
28-
$this->tagsRelation()->detach();
27+
$this->tagsRelation()->detach($tags);
28+
}
29+
30+
public function tagCount(): int
31+
{
32+
return $this->tags()->count();
2933
}
3034
}

src/Traits/RouteKeyNameSlug.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Miladimos\Toolkit\Traits;
4+
5+
trait RouteKeyNameSlug
6+
{
7+
/**
8+
* Get the route key for the model.
9+
*
10+
* @return string
11+
*/
12+
public function getRouteKeyName()
13+
{
14+
return 'slug';
15+
}
16+
}

0 commit comments

Comments
 (0)