Skip to content

Commit

Permalink
Fix typos and update method arguments in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPunyapal committed Dec 10, 2023
1 parent 26bf340 commit bb82551
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
### What is a need of extended relationships?
The laravel-extended-relationships package provides additional, more efficient relationship methods for Laravel Eloquent models. The package offers several useful features such as reducing the number of database queries, improving performance, and minimizing duplicate code.

I faced issue and made my own relationships then realise if I can use packages from open source then I can make one too and made this package.
I faced issue and made my own relationships then realize if I can use packages from open source then I can make one too and made this package.

## Installation

Expand Down Expand Up @@ -39,9 +39,9 @@ Next, define the `BelongsToManyKeys` relationship with the `belongsToManyKeys` m

public function auditors() {
return $this->belongsToManyKeys(
User::class,
'id',
[
related: User::class,
foreignKey: 'id',
relations: [
'created_by' => 'creator',
'updated_by' => 'updater',
'deleted_by' => 'deleter',
Expand Down Expand Up @@ -105,13 +105,13 @@ class User extends Model{

public function audited(){
return $this->hasManyKeys(
Post::class,
[
related: Post::class,
relations: [
'created_by' => 'created',
'updated_by' => 'updated',
'deleted_by' => 'deleted',
],
'id'
localKey: 'id'
);
}
}
Expand Down Expand Up @@ -169,9 +169,9 @@ class User extends Model
public function myCompanies()
{
return $this->hasManyArrayColumn(
Company::class,
'id',
'companies'
related: Company::class,
foreignKey: 'id',
localKey: 'companies'
);
}
}
Expand All @@ -193,7 +193,10 @@ This allows you to easily retrieve related records with an array of local keys,

### Inverse Relationship for `HasManyArrayColumn`

The `BelongsToArrayColumn` method allows you to define a relationship between a model and an array column on another model. Here's an example:
The `BelongsToArrayColumn` method allows you to define a relationship between a model and an array column on another model.
if you have ["7", "71"] in array column and int 7 or 71 at your foreign-key then pass `$isString` flag as true to get expected results.

Here's an example:

```php

Expand All @@ -206,10 +209,11 @@ class Company extends Model
public function companyFounders()
{
return $this->belongsToArrayColumn(
User::class,
'id',
'companies',
true // optional, default is false (if true then it treats all values as string)
related: User::class,
foreignKey: 'id',
localKey: 'companies',
// optional, default is false (if true then it treats all values as string)
isString: true
);
}
}
Expand Down

0 comments on commit bb82551

Please sign in to comment.