Skip to content

Commit

Permalink
modify scope method Repository abstract and change stub repositoryGen…
Browse files Browse the repository at this point in the history
…erator
  • Loading branch information
mohamadtsn committed May 15, 2022
1 parent ae139ae commit b3d0836
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Commands/RepositoryMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RepositoryMakeCommand extends GeneratorCommand
*
* @var string
*/
protected $signature = 'make:repository {name} {--model=}';
protected $signature = 'make:repository {name} {--M|model=}';

/**
* The console command description.
Expand Down
7 changes: 3 additions & 4 deletions src/Commands/stubs/repository.stub
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ use {{ namespacedModel }};

class {{ class }} extends Repository
{

protected function init(): Builder
public function init(): Builder
{
return {{ model }}::query();
}

protected function instanceModel(): {{ model }}
public function instanceModel(): {{ model }}
{
return new {{ model }}();
}

protected function modelName(): string
public static function modelName(): string
{
return "{{ model }}";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ abstract class Repository

abstract public function init(): Builder;
abstract public function instanceModel(): Model;
abstract public function modelName(): string;
abstract public static function modelName(): string;

}
7 changes: 1 addition & 6 deletions src/Providers/RepositoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ class RepositoryServiceProvider extends ServiceProvider
public function register()
{
// +|i|+ => register Repositories --help
$this->app->bind('SampleRepository' /* enter Repository class name */, static function () {
$this->app->singleton('SampleRepository' /* enter Repository class name */, static function () {
// +|i|+ => new instance from Repository --help

// return new SampleRepository();
});
}

public function boot()
{
//
}
}
6 changes: 3 additions & 3 deletions src/Repositories/SampleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
class SampleRepository extends Repository
{

protected function init(): Builder
public function init(): Builder
{
// Sample
// return User::query();
}

protected function instanceModel(): Model
public function instanceModel(): Model
{
// Sample
// return new User();
}

protected function modelName(): string
public static function modelName(): string
{
// Sample
return 'User';
Expand Down

0 comments on commit b3d0836

Please sign in to comment.