Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use ReflectionClass;
use ReflectionProperty;
use DatabaseFactory\Facades;
use DatabaseFactory\ORM;
use DatabaseFactory\Facades;

/**
* The base entity class
Expand All @@ -20,7 +21,8 @@
class Entity
{
// ORM Plugins
use \DatabaseFactory\ORM\HasTable;
use ORM\HasTable;
use ORM\HasQuery;

/**
* ID of a record for updating
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/HasAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
trait HasAll
{
public static function all(string $columns = '*'): Builder
public static function all(string $columns = '*')
{
return Facades\DB::table(static::table())->select($columns);
return Facades\DB::table(static::table())->select($columns)->get();
}
}
}
4 changes: 2 additions & 2 deletions src/ORM/HasFind.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
trait HasFind
{
public static function find(int $id, string $columns = '*'): Builder
public static function find(int|string $value, string $by = 'id', string $columns = '*')
{
return Facades\DB::table(static::table())->select($columns)->where('id', '=', $id);
return Facades\DB::table(static::table())->select($columns)->where($by, '=', $value)->get();
}
}
}
4 changes: 2 additions & 2 deletions src/ORM/HasFirst.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*/
trait HasFirst
{
public static function first(string $columns = '*'): Builder
public static function first(string $columns = '*')
{
return Facades\DB::table(static::table())->select($columns)->orderBy('id', 'ASC')->limit(1);
return Facades\DB::table(static::table())->select($columns)->orderBy('id', 'ASC')->limit(1)->get();
}
}
}
4 changes: 2 additions & 2 deletions src/ORM/HasJoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
trait HasJoin
{
public static function join(string $table, array $on, string $columns = '*'): Builder
public static function join(string $table, array $on, string $columns = '*')
{
return Facades\DB::table(static::table())->join($table, $on, $columns);
return Facades\DB::table(static::table())->join($table, $on, $columns)->get();
}
}
}
4 changes: 2 additions & 2 deletions src/ORM/HasLast.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*/
trait HasLast
{
public static function last(string $columns = '*'): Builder
public static function last(string $columns = '*')
{
return Facades\DB::table(static::table())->select($columns)->orderBy('id', 'DESC')->limit(1);
return Facades\DB::table(static::table())->select($columns)->orderBy('id', 'DESC')->limit(1)->get();
}
}
}
4 changes: 2 additions & 2 deletions src/ORM/HasLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
trait HasLike
{
public static function like(string $field, string $pattern, string $columns = '*'): Builder
public static function like(string $field, string $pattern, string $columns = '*')
{
return Facades\DB::table(static::table())->select($columns)->like($field, $pattern);
return Facades\DB::table(static::table())->select($columns)->like($field, $pattern)->get();
}
}
}
4 changes: 2 additions & 2 deletions src/ORM/HasNot.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
trait HasNot
{
public static function whereNot($key = null, $value = null, string $columns = '*'): Builder
public static function whereNot($key = null, $value = null, string $columns = '*')
{
return Facades\DB::table(static::table())->select($columns)->whereNot($key, $value);
return Facades\DB::table(static::table())->select($columns)->whereNot($key, $value)->get();
}
}
}
16 changes: 16 additions & 0 deletions src/ORM/HasQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace DatabaseFactory\ORM {

use DatabaseFactory\Config;
use DatabaseFactory\Facades;
use DatabaseFactory\Builder;

trait HasQuery
{
public static function query(string $config = Config::class): Builder
{
return Facades\DB::table(static::table(), $config);
}
}
}
4 changes: 2 additions & 2 deletions src/ORM/HasWhere.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*/
trait HasWhere
{
public static function where($key, $is = null, $value = null, string $columns = '*'): Builder
public static function where($key, $is = null, $value = null, string $columns = '*')
{
return Facades\DB::table(static::table())->select($columns)->where($key, $is, $value);
return Facades\DB::table(static::table())->select($columns)->where($key, $is, $value)->get();
}
}
}