• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

conedevelopment / root / 20694177656

04 Jan 2026 02:13PM UTC coverage: 74.594% (-0.5%) from 75.049%
20694177656

push

github

iamgergo
version

3491 of 4680 relevant lines covered (74.59%)

32.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.79
/src/Fields/MorphToMany.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Cone\Root\Fields;
6

7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Database\Eloquent\Model;
9
use Illuminate\Database\Eloquent\Relations\BelongsTo as BelongsToRelation;
10
use Illuminate\Database\Eloquent\Relations\MorphPivot;
11
use Illuminate\Database\Eloquent\Relations\MorphToMany as EloquentRelation;
12
use Illuminate\Http\Request;
13
use Illuminate\Support\Uri;
14

15
/**
16
 * @extends \Cone\Root\Fields\BelongsToMany<\Illuminate\Database\Eloquent\Relations\MorphToMany>
17
 */
18
class MorphToMany extends BelongsToMany
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function getRelation(Model $model): EloquentRelation
9✔
24
    {
25
        return parent::getRelation($model);
9✔
26
    }
27

28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function fields(Request $request): array
×
32
    {
33
        return [
×
34
            BelongsTo::make($this->getRelatedName(), 'related', static function (Model $model): BelongsToRelation {
×
35
                return $model->belongsTo(
×
36
                    $model::class,
×
37
                    $model->getRelatedKey(),
×
38
                    $model->getForeignKey()
×
39
                )->withDefault();
×
40
            })->withRelatableQuery(function (Request $request, Builder $query, Model $model): Builder {
×
41
                return $this->resolveRelatableQuery($request, $model->pivotParent)
×
42
                    ->unless($this->allowDuplicateRelations, function (Builder $query) use ($model): Builder {
×
43
                        return $query->whereNotIn(
×
44
                            $query->getModel()->getQualifiedKeyName(),
×
45
                            $this->getRelation($model->pivotParent)
×
46
                                ->select($query->getModel()->getQualifiedKeyName())
×
47
                                ->whereNot(
×
48
                                    $query->getModel()->getQualifiedKeyName(),
×
49
                                    $model->getAttribute($model->getRelatedKey())
×
50
                                )
×
51
                        );
×
52
                    });
×
53
            })->hydrate(function (Request $request, MorphPivot $model, mixed $value): void {
×
54
                $model->setAttribute(
×
55
                    $this->getRelation($model->pivotParent)->getRelatedPivotKeyName(),
×
56
                    $value
×
57
                );
×
58
            })->display(fn (Model $model): ?string => $this->resolveDisplay($model)),
×
59
        ];
×
60
    }
61

62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function toInput(Request $request, Model $model): array
2✔
66
    {
67
        $data = parent::toInput($request, $model);
2✔
68

69
        if (! empty($data['url'])) {
2✔
70
            $relation = $this->getRelation($model);
×
71

72
            $data['url'] = Uri::of($data['url'])
×
73
                ->withQuery([$relation->getMorphType() => $relation->getRelated()::class])
×
74
                ->value();
×
75
        }
76

77
        return $data;
2✔
78
    }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc