Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
MorphToManyOrderable
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
1
 newPivotQuery
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Baril\Orderly\Relations;
4
5use Illuminate\Database\Eloquent\Builder;
6use Illuminate\Database\Eloquent\Model;
7use Illuminate\Database\Eloquent\Relations\MorphToMany;
8
9/**
10 * Many to many relation with ordering support.
11 */
12class MorphToManyOrderable extends MorphToMany
13{
14    use Concerns\InteractsWithOrderablePivotTable {
15        newPivotQuery as _newPivotQuery;
16    }
17
18    /**
19     * Create a new morph to many relationship instance.
20     *
21     * @param Builder $query
22     * @param Model   $parent
23     * @param string  $name
24     * @param string  $orderColumn
25     * @param string  $table
26     * @param string  $foreignPivotKey
27     * @param string  $relatedPivotKey
28     * @param string  $parentKey
29     * @param string  $relatedKey
30     * @param string  $relationName
31     * @param bool    $inverse
32     */
33    public function __construct(
34        Builder $query,
35        Model $parent,
36        $name,
37        $orderColumn,
38        $table,
39        $foreignPivotKey,
40        $relatedPivotKey,
41        $parentKey,
42        $relatedKey,
43        $relationName = null,
44        $inverse = false
45    ) {
46        parent::__construct(
47            $query,
48            $parent,
49            $name,
50            $table,
51            $foreignPivotKey,
52            $relatedPivotKey,
53            $parentKey,
54            $relatedKey,
55            $relationName,
56            $inverse
57        );
58        $this->setOrderColumn($orderColumn);
59    }
60
61    /**
62     * Create a new query builder for the pivot table.
63     *
64     * @param boolean $ordered
65     * @return \Illuminate\Database\Query\Builder
66     */
67    public function newPivotQuery($ordered = true)
68    {
69        return $this->_newPivotQuery($ordered)->where($this->morphType, $this->morphClass);
70    }
71}