Download the PHP package fico7489/laravel-pivot without Composer

On this page you can find all versions of the php package fico7489/laravel-pivot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-pivot

Laravel Pivot

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

Laravel Problems

In Laravel events are not dispatched when BelongsToMany relation (pivot table) is updated with sync(), attach(), detach() or updateExistingPivot() methods, but this package will help with that.

Version Compatibility

Laravel Version Package Tag Supported Development Branch
>= 5.5.0 3.* yes master
< 5.5.0 - no -

Install

1.Install package with composer

With this statement, a composer will install highest available package version for your current laravel version.

2.Use Fico7489\Laravel\Pivot\Traits\PivotEventTrait trait in your base model or only in particular models.

and that's it, enjoy.

New eloquent events

You can check all eloquent events here: https://laravel.com/docs/5.5/eloquent#events)

New events are :

The best way to catch events is with this model functions:

You can also see those events here:

Suported relations

BelongsToMany and MorphToMany

Which events are dispatched and when they are dispatched

Four BelongsToMany methods dispatches events from this package:

attach()
Dispatches one pivotAttaching and one pivotAttached event.
Even when more rows are added only one event is dispatched for all rows but in that case, you can see all changed row ids in the $pivotIds variable, and the changed row ids with attributes in the $pivotIdsAttributes variable.

detach()
Dispatches one pivotDetaching and one pivotDetached event.
Even when more rows are deleted only one event is dispatched for all rows but in that case, you can see all changed row ids in the $pivotIds variable.

updateExistingPivot()
Dispatches one pivotUpdating and one pivotUpdated event.
You can change only one row in the pivot table with updateExistingPivot.

sync()
Dispatches more pivotAttaching and more pivotAttached events, depending on how many rows are added in the pivot table. These events are not dispatched if nothing is attached.
Dispatches one pivotDetaching and one pivotDetached event, but you can see all deleted ids in the $pivotIds variable. This event is not dispatched if nothing is detached.
Dispatches more pivotUpdating and more pivotUpdated events, depending on how many rows are updated in the pivot table. These events are not dispatched if nothing is attached.

E.g. when you call sync() if two rows are added and two are deleted two pivotAttaching and two pivotAttached events and one pivotDetaching and one pivotDetached event will be dispatched.
If sync() is called but rows are not added or deleted events are not dispatched.

Usage

We have three tables in database users(id, name), roles(id, name), role_user(user_id, role_id). We have two models :

Attaching

For attach() or detach() one event is dispatched for both pivot ids.

Attaching with int

Running this code

You will see this output

Attaching with array

Running this code

You will see this output

Attaching with model

Running this code

You will see this output

Attaching with collection

Running this code

You will see this output

Attaching with array (id => attributes)

Running this code

You will see this output

Syncing:

For sync() method event is dispatched for each pivot row.

Running this code

You will see this output

Detaching:

Running this code

You will see this output

Updating:

Running this code

You will see this output

License

MIT

Free Software, Hell Yeah!


All versions of laravel-pivot with dependencies

PHP Build Version
Package Version
Requires illuminate/database Version 5.5.*|6.*|7.*|8.*|9.*|10.*|11.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package fico7489/laravel-pivot contains the following files

Loading the files please wait ....