Skip to content

Commit 732c71f

Browse files
Merge pull request #39 from jason-napolitano/master
ORM Changes
2 parents 99077fd + 2dc0f32 commit 732c71f

File tree

10 files changed

+36
-18
lines changed

10 files changed

+36
-18
lines changed

src/Entity.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
use ReflectionClass;
66
use ReflectionProperty;
7-
use DatabaseFactory\Facades;
7+
use DatabaseFactory\ORM;
8+
use DatabaseFactory\Facades;
89

910
/**
1011
* The base entity class
@@ -20,7 +21,8 @@
2021
class Entity
2122
{
2223
// ORM Plugins
23-
use \DatabaseFactory\ORM\HasTable;
24+
use ORM\HasTable;
25+
use ORM\HasQuery;
2426

2527
/**
2628
* ID of a record for updating

src/ORM/HasAll.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
*/
1818
trait HasAll
1919
{
20-
public static function all(string $columns = '*'): Builder
20+
public static function all(string $columns = '*')
2121
{
22-
return Facades\DB::table(static::table())->select($columns);
22+
return Facades\DB::table(static::table())->select($columns)->get();
2323
}
2424
}
2525
}

src/ORM/HasFind.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
*/
1818
trait HasFind
1919
{
20-
public static function find(int $id, string $columns = '*'): Builder
20+
public static function find(int|string $value, string $by = 'id', string $columns = '*')
2121
{
22-
return Facades\DB::table(static::table())->select($columns)->where('id', '=', $id);
22+
return Facades\DB::table(static::table())->select($columns)->where($by, '=', $value)->get();
2323
}
2424
}
2525
}

src/ORM/HasFirst.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*/
2020
trait HasFirst
2121
{
22-
public static function first(string $columns = '*'): Builder
22+
public static function first(string $columns = '*')
2323
{
24-
return Facades\DB::table(static::table())->select($columns)->orderBy('id', 'ASC')->limit(1);
24+
return Facades\DB::table(static::table())->select($columns)->orderBy('id', 'ASC')->limit(1)->get();
2525
}
2626
}
2727
}

src/ORM/HasJoin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
*/
1818
trait HasJoin
1919
{
20-
public static function join(string $table, array $on, string $columns = '*'): Builder
20+
public static function join(string $table, array $on, string $columns = '*')
2121
{
22-
return Facades\DB::table(static::table())->join($table, $on, $columns);
22+
return Facades\DB::table(static::table())->join($table, $on, $columns)->get();
2323
}
2424
}
2525
}

src/ORM/HasLast.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*/
2020
trait HasLast
2121
{
22-
public static function last(string $columns = '*'): Builder
22+
public static function last(string $columns = '*')
2323
{
24-
return Facades\DB::table(static::table())->select($columns)->orderBy('id', 'DESC')->limit(1);
24+
return Facades\DB::table(static::table())->select($columns)->orderBy('id', 'DESC')->limit(1)->get();
2525
}
2626
}
2727
}

src/ORM/HasLike.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
*/
1818
trait HasLike
1919
{
20-
public static function like(string $field, string $pattern, string $columns = '*'): Builder
20+
public static function like(string $field, string $pattern, string $columns = '*')
2121
{
22-
return Facades\DB::table(static::table())->select($columns)->like($field, $pattern);
22+
return Facades\DB::table(static::table())->select($columns)->like($field, $pattern)->get();
2323
}
2424
}
2525
}

src/ORM/HasNot.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
*/
1919
trait HasNot
2020
{
21-
public static function whereNot($key = null, $value = null, string $columns = '*'): Builder
21+
public static function whereNot($key = null, $value = null, string $columns = '*')
2222
{
23-
return Facades\DB::table(static::table())->select($columns)->whereNot($key, $value);
23+
return Facades\DB::table(static::table())->select($columns)->whereNot($key, $value)->get();
2424
}
2525
}
2626
}

src/ORM/HasQuery.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace DatabaseFactory\ORM {
4+
5+
use DatabaseFactory\Config;
6+
use DatabaseFactory\Facades;
7+
use DatabaseFactory\Builder;
8+
9+
trait HasQuery
10+
{
11+
public static function query(string $config = Config::class): Builder
12+
{
13+
return Facades\DB::table(static::table(), $config);
14+
}
15+
}
16+
}

src/ORM/HasWhere.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*/
2020
trait HasWhere
2121
{
22-
public static function where($key, $is = null, $value = null, string $columns = '*'): Builder
22+
public static function where($key, $is = null, $value = null, string $columns = '*')
2323
{
24-
return Facades\DB::table(static::table())->select($columns)->where($key, $is, $value);
24+
return Facades\DB::table(static::table())->select($columns)->where($key, $is, $value)->get();
2525
}
2626
}
2727
}

0 commit comments

Comments
 (0)