Skip to content

Commit

Permalink
Renamed Package
Browse files Browse the repository at this point in the history
  • Loading branch information
ahawlitschek committed Mar 22, 2024
1 parent 06d8aa9 commit 3d92fc6
Show file tree
Hide file tree
Showing 29 changed files with 129 additions and 181 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# This is my package laravel-power-relations
# Laravel Custom Relations

[![Latest Version on Packagist](https://img.shields.io/packagist/v/53199186-ahawlitschek/laravel-power-relations.svg?style=flat-square)](https://packagist.org/packages/53199186-ahawlitschek/laravel-power-relations)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/53199186-ahawlitschek/laravel-power-relations/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/53199186-ahawlitschek/laravel-power-relations/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/53199186-ahawlitschek/laravel-power-relations/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/53199186-ahawlitschek/laravel-power-relations/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/53199186-ahawlitschek/laravel-power-relations.svg?style=flat-square)](https://packagist.org/packages/53199186-ahawlitschek/laravel-power-relations)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
When you need more control over your relations.

## Introduction
Sometimes you will need some more power 🔋💪🏻

This package extends the default Laravel Relations with Relations that can be described by a query.

Considering the following models:
Expand Down Expand Up @@ -42,12 +41,12 @@ composer require clickbar/laravel-power-relations
In order to use the Power Relations, you must use the ``HasPowerRelation`` trait:

```php
use Clickbar\LaravelPowerRelations\Traits\HasPowerRelation;
use Clickbar\LaravelCustomRelations\Traits\HasCustomRelation;


class Client extends Model{

use HasPowerRelation;
use HasCustomRelation;

...
}
Expand Down
21 changes: 9 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "53199186-ahawlitschek/laravel-power-relations",
"description": "This is my package laravel-power-relations",
"name": "clickbar/laravel-custom-relations",
"description": "This package provides functionality for custom relations in laravel",
"keywords": [
"clickbar",
"laravel",
"laravel-power-relations"
"laravel-custom-relations"
],
"homepage": "https://github.com/clickbar/laravel-power-relations",
"license": "MIT",
Expand Down Expand Up @@ -34,19 +34,19 @@
},
"autoload": {
"psr-4": {
"Clickbar\\LaravelPowerRelations\\": "src/",
"Clickbar\\LaravelPowerRelations\\Database\\Factories\\": "database/factories/"
"Clickbar\\LaravelCustomRelations\\": "src/",
"Clickbar\\LaravelCustomRelations\\Database\\Factories\\": "database/factories/"
}
},
"autoload-dev": {
"psr-4": {
"Clickbar\\LaravelPowerRelations\\Tests\\": "tests/",
"Clickbar\\LaravelCustomRelations\\Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/"
}
},
"scripts": {
"post-autoload-dump": "@composer run prepare",
"clear": "@php vendor/bin/testbench package:purge-laravel-power-relations --ansi",
"clear": "@php vendor/bin/testbench package:purge-laravel-custom-relations --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": [
"@composer run prepare",
Expand All @@ -72,11 +72,8 @@
"extra": {
"laravel": {
"providers": [
"Clickbar\\LaravelPowerRelations\\LaravelPowerRelationsServiceProvider"
],
"aliases": {
"LaravelPowerRelations": "Clickbar\\LaravelPowerRelations\\Facades\\LaravelPowerRelations"
}
"LaravelCustomRelationsServiceProvider"
]
}
},
"minimum-stability": "dev",
Expand Down
19 changes: 0 additions & 19 deletions src/Commands/LaravelPowerRelationsCommand.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Eloquent/ColumnsTransformator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Clickbar\LaravelPowerRelations\Eloquent;
namespace Clickbar\LaravelCustomRelations\Eloquent;

use Illuminate\Contracts\Database\Query\Expression;
use Illuminate\Database\Grammar;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Clickbar\LaravelPowerRelations\Eloquent\Relation;
namespace Clickbar\LaravelCustomRelations\Eloquent\Relation;

use Clickbar\LaravelPowerRelations\Eloquent\ColumnsTransformator;
use Clickbar\LaravelCustomRelations\Eloquent\ColumnsTransformator;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -15,7 +15,7 @@
*
* @mixin Builder<TModelClass>
*/
class PowerRelation extends Relation
class CustomRelation extends Relation
{
public function __construct(
Model $parent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace Clickbar\LaravelPowerRelations\Eloquent\Relation;
namespace Clickbar\LaravelCustomRelations\Eloquent\Relation;

/**
* @template TModelClass of \Illuminate\Database\Eloquent\Model
*
* @extends PowerRelation<TModelClass>
* @extends CustomRelation<TModelClass>
*/
class PowerRelationSingle extends PowerRelation
class CustomRelationSingle extends CustomRelation
{
/**
* Initialize the relation on a set of models.
Expand Down
16 changes: 0 additions & 16 deletions src/Facades/LaravelPowerRelations.php

This file was deleted.

19 changes: 19 additions & 0 deletions src/LaravelCustomRelationsServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Clickbar\LaravelCustomRelations;

use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

class LaravelCustomRelationsServiceProvider extends PackageServiceProvider
{
public function configurePackage(Package $package): void
{
/*
* This class is a Package Service Provider
*
* More info: https://github.com/spatie/laravel-package-tools
*/
$package->name('laravel-custom-relations');
}
}
7 changes: 0 additions & 7 deletions src/LaravelPowerRelations.php

This file was deleted.

25 changes: 0 additions & 25 deletions src/LaravelPowerRelationsServiceProvider.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?php

namespace Clickbar\LaravelPowerRelations\Traits;
namespace Clickbar\LaravelCustomRelations\Traits;

use Clickbar\LaravelPowerRelations\Eloquent\Relation\PowerRelation;
use Clickbar\LaravelPowerRelations\Eloquent\Relation\PowerRelationSingle;
use Clickbar\LaravelCustomRelations\Eloquent\Relation\CustomRelation;
use Clickbar\LaravelCustomRelations\Eloquent\Relation\CustomRelationSingle;
use Illuminate\Database\Eloquent\Model;

/**
* @mixin Model
*/
trait HasPowerRelation
trait HasCustomRelation
{
/**
* @template TModelClass of Model
*
* @param class-string<TModelClass> $related
* @return PowerRelation<TModelClass>
* @return CustomRelation<TModelClass>
*/
public function powerRelation(string $related, \Closure $relationQueryCallback, ?string $localKey = null): PowerRelation
public function customRelation(string $related, \Closure $relationQueryCallback, ?string $localKey = null): CustomRelation
{
/** @var Model */
$relatedInstance = $this->newRelatedInstance($related);

return new PowerRelation(
return new CustomRelation(
parent: $this,
relatedInstance: $relatedInstance,
relationQueryCallback: $relationQueryCallback,
Expand All @@ -34,14 +34,14 @@ public function powerRelation(string $related, \Closure $relationQueryCallback,
* @template TModelClass of Model
*
* @param class-string<TModelClass> $related
* @return PowerRelation<TModelClass>
* @return CustomRelation<TModelClass>
*/
public function powerRelationFromParent(string $related, \Closure $relationQueryCallback, ?string $localKey = null): PowerRelation
public function customRelationFromParent(string $related, \Closure $relationQueryCallback, ?string $localKey = null): CustomRelation
{
/** @var Model */
$relatedInstance = $this->newRelatedInstance($related);

return new PowerRelation(
return new CustomRelation(
parent: $this,
relatedInstance: $relatedInstance,
relationQueryCallback: $relationQueryCallback,
Expand All @@ -53,15 +53,15 @@ public function powerRelationFromParent(string $related, \Closure $relationQuery
* @template TModelClass of Model
*
* @param class-string<TModelClass> $related
* @return PowerRelationSingle<TModelClass>
* @return CustomRelationSingle<TModelClass>
*/
public function powerRelationSingle(string $related, \Closure $relationQueryCallback, ?string $localKey = null): PowerRelationSingle
public function customRelationSingle(string $related, \Closure $relationQueryCallback, ?string $localKey = null): CustomRelationSingle
{
/** @var Model */
$relatedInstance = $this->newRelatedInstance($related);

/** @var PowerRelationSingle<TModelClass> */
return new PowerRelationSingle(
/** @var CustomRelationSingle<TModelClass> */
return new CustomRelationSingle(
parent: $this,
relatedInstance: $relatedInstance,
relationQueryCallback: $relationQueryCallback,
Expand All @@ -73,15 +73,15 @@ public function powerRelationSingle(string $related, \Closure $relationQueryCall
* @template TModelClass of Model
*
* @param class-string<TModelClass> $related
* @return PowerRelationSingle<TModelClass>
* @return CustomRelationSingle<TModelClass>
*/
public function powerRelationFromParentSingle(string $related, \Closure $relationQueryCallback, ?string $localKey = null): PowerRelationSingle
public function customRelationFromParentSingle(string $related, \Closure $relationQueryCallback, ?string $localKey = null): CustomRelationSingle
{
/** @var Model */
$relatedInstance = $this->newRelatedInstance($related);

/** @var PowerRelationSingle<TModelClass> */
return new PowerRelationSingle(
/** @var CustomRelationSingle<TModelClass> */
return new CustomRelationSingle(
parent: $this,
relatedInstance: $relatedInstance,
relationQueryCallback: $relationQueryCallback,
Expand Down
2 changes: 1 addition & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

use Clickbar\LaravelPowerRelations\Tests\TestCase;
use Clickbar\LaravelCustomRelations\Tests\TestCase;

uses(TestCase::class)->in(__DIR__);
8 changes: 4 additions & 4 deletions tests/ReadOnlyTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Client;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Order;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Project;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Task;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Client;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Order;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Project;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Task;
use Illuminate\Support\Facades\DB;

it('throws error when trying to make a record on relation', function () {
Expand Down
10 changes: 5 additions & 5 deletions tests/RelationDeleteTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Client;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Order;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Project;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Task;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\TaskWithSoftDelete;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Client;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Order;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Project;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Task;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\TaskWithSoftDelete;

it('can delete tasks of client via PowerRelation', function () {

Expand Down
8 changes: 4 additions & 4 deletions tests/RelationEagerLoadTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Client;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Order;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Project;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Task;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Client;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Order;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Project;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Task;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

Expand Down
10 changes: 5 additions & 5 deletions tests/RelationRetrieveTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Client;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Order;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Project;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Task;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\TaskWithSoftDelete;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Client;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Order;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Project;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Task;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\TaskWithSoftDelete;

it('can retrieve tasks of client via PowerRelation', function () {

Expand Down
8 changes: 4 additions & 4 deletions tests/RelationWhereHasTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Client;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Order;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Project;
use Clickbar\LaravelPowerRelations\Tests\TestClasses\Models\Task;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Client;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Order;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Project;
use Clickbar\LaravelCustomRelations\Tests\TestClasses\Models\Task;

it('can use whereHas on tasks of client via PowerRelation', function () {

Expand Down
Loading

0 comments on commit 3d92fc6

Please sign in to comment.