Issues (3)

src/InsertTrait.php (1 issue)

1
<?php
2
3
namespace Blasttech\EloquentRelatedPlus;
4
5
use Illuminate\Database\Eloquent\Builder;
6
7
/**
8
 * Trait InsertSelect
9
 * @package App\Http\Traits
10
 *
11
 * @method bool insertSelect(Builder $builder, array $insertColumns = [])
12
 */
13
trait InsertTrait
14
{
15
    use HelpersTrait;
16
17
    /**
18
     * InsertSelect - builds SQL for 'INSERT INTO tablename (field1, field2) FROM SELECT a1, a2 FROM table2'
19
     *
20
     * @param Builder $query - the Builder to insert into
21
     * @param Builder $builder - the Query Builder to select from
22
     * @param array $insertColumns - the columns to insert into
23
     * @return bool
24
     */
25
    public function scopeInsertSelect(Builder $query, Builder $builder, array $insertColumns = [])
26
    {
27
        $insert = 'INSERT INTO ' . $query->getModel()->getTable();
28
29
        if (!empty($insertColumns)) {
30
            $insert .= ' (' . implode(', ', $insertColumns) . ')';
31
        }
32
33
        $insert .= ' ' . $this->toSqlWithBindings($builder);
34
35
        return $query->getConnection()->statement($insert);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->getConnec...n()->statement($insert) also could return the type Illuminate\Database\Conn...tabase\Eloquent\Builder which is incompatible with the documented return type boolean.
Loading history...
36
    }
37
}
38