Skip to content

Quickly define relationships between eloquent models with a simple command

License

Notifications You must be signed in to change notification settings

yassinya/laravel-relationships-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This package allows you to define relationships between your models directly from the command line instead of creating them then setting the relationship methods manually.

Most of the Laravel relationships are supported, including polymorphic ones.

Installation

This package can be installed via composer:

composer require yassinya/laravel-relation-cli

The service provider will be automatically registered

Publish the config file with:

php artisan vendor:publish --provider="Yassinya\Relation\RelationServiceProvider" --tag="config"

Usage

To define a relationship you'll need to use the relation command which expects 3 required arguments:

  1. The main model's name
  2. The type of the relationship

The following abbreviations are used for the relationships

  • One To One -> 121
  • One to Many -> 12m
  • Many to Many -> m2m
  1. Name of the target model

One to One

php artisan relation User 121 Phone

It'll first try to find The models then edit them, and if they don't exist they'll be created

One to Many

php artisan relation Library 12m Book

Many to Many

php artisan relation User m2m Product

Polymorphic Relationships

To define a polymorphic relationship just add the -p or --polymorphic option. For instance to define a 121 polymorphic relationship between Post and Image

php artisan relation Post 121 Image -p

Between User and Image

php artisan relation User 121 Image -p

About

Quickly define relationships between eloquent models with a simple command

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages