-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from nonetallt/feature-through-relationships
Add missing relationships from Laravel core and support custom relationships from external packages.
- Loading branch information
Showing
7 changed files
with
428 additions
and
497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
return [ | ||
/** | ||
* Custom relationships allows you to add support for relationships from | ||
* extenal packages that are not a part of the Laravel core. Note that | ||
* relationship method names are case sensitive. | ||
* | ||
*/ | ||
'custom_relationships' => [ | ||
'singular' => [ | ||
// custom relationships that return a single model | ||
// 'belongsToThrough', | ||
], | ||
'plural' => [ | ||
// custom relationships that return multiple models | ||
] | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace FumeApp\ModelTyper\Commands; | ||
|
||
use Illuminate\Database\Console\ShowModelCommand as BaseCommand; | ||
|
||
/** | ||
* A wrapper command for Laravel default model:show to add customizaton for model generation. | ||
* | ||
*/ | ||
class ShowModelCommand extends BaseCommand | ||
{ | ||
protected $name = 'model:typer-show {model}'; | ||
|
||
protected $signature = 'model:typer-show {model : The model to show} | ||
{--custom-relationships= : Custom relationships that should be included, separated by commas} | ||
{--database= : The database connection to use} | ||
{--json : Output the model as JSON}'; | ||
|
||
public function handle() | ||
{ | ||
$customRelationships = collect(explode(',', $this->option('custom-relationships')))->map(fn($method) => trim($method)); | ||
$this->relationMethods = array_merge($this->relationMethods, $customRelationships->toArray()); | ||
|
||
parent::handle(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters