Skip to content

Commit

Permalink
Fix Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferry Ariawan committed Mar 4, 2021
1 parent 0657de9 commit 18983a3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
12 changes: 1 addition & 11 deletions src/Helpers/BuilderMacro.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
<?php


namespace Crocodic\LaravelModel\Helpers;


use Illuminate\Database\Query\Builder;
use Illuminate\Support\Str;

class BuilderMacro
{
private static function getFields(string $table)
{
$modelName = "\App\Models\\".Str::studly($table)."Model";
$modelClass = new $modelName();
return get_object_vars($modelClass);
}

public static function registerMacro()
{
Builder::macro("addSelectTable", function($table) {
$fields = static::getFields($table);
$fields = Helper::getFields($table);
foreach($fields as $field) {
$this->addSelect($table.".".$field." as ".$table."_".$field);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Helper
{
public static function getFields(string $table)
{
$modelName = Str::studly($table)."Model";
$modelClass = new ("\App\Models\\".$modelName)();
$modelName = "\App\Models\\".Str::studly($table)."Model";
$modelClass = new $modelName();
return get_object_vars($modelClass);
}

Expand Down

0 comments on commit 18983a3

Please sign in to comment.