Skip to content

Instantly share code, notes, and snippets.

@omarkdev
Created December 20, 2016 01:56
Show Gist options
  • Save omarkdev/5b81e56013eb97afab45c8de884e2090 to your computer and use it in GitHub Desktop.
Save omarkdev/5b81e56013eb97afab45c8de884e2090 to your computer and use it in GitHub Desktop.
<?php
namespace ArtisanPlus\Repositories;
use Illuminate\Support\Facades\Schema;
use Carbon\Carbon;
class TableRepository {
/**
* Implements orderBy in query
*
* @param $query
* @param $orderBy
*
* @return mixed
*/
public function orderBy($query, $orderBy)
{
$orderBy = explode(",", $orderBy);
$orderBy[1] = (isset($orderBy[1])) ? $orderBy[1] : null;
return $query->orderBy($orderBy[0], $orderBy[1]);
}
/**
* Converts results to array to use in table
*
* @param $results
*
* @return array
*/
public function convertToArray($results)
{
return array_map(function($result) {
return (array) $result;
}, $results);
}
/**
* Return list of columns from table
*
* @param $table
*
* @return mixed
*/
public function getColumnsTable($table)
{
return Schema::getColumnListing($table);
}
/**
* Return fields to use in columns of model structure
*
* @return array
*/
public function getTimestampsModel()
{
return [
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment