Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 5.4 support and multiselect field in table #159

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static function appendRoutes($config, $comm = null)
$templateDirectory = __DIR__ . '/stubs';

LAHelper::log("info", "Appending routes...", $comm);
if(\Dwij\Laraadmin\Helpers\LAHelper::laravel_ver() == 5.3) {
if(\Dwij\Laraadmin\Helpers\LAHelper::is_recent_laravel_version()) {
$routesFile = base_path('routes/admin_routes.php');
} else {
$routesFile = app_path('Http/admin_routes.php');
Expand Down
148 changes: 74 additions & 74 deletions src/Commands/LAInstall.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Commands/Packaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function handle()

// Routes
$this->line('Exporting Routes...');
if(LAHelper::laravel_ver() == 5.3) {
if(LAHelper::is_recent_laravel_version()) {
// $this->copyFile($from."/routes/web.php", $to."/app/routes.php"); // Not needed anymore
$this->copyFile($from . "/routes/admin_routes.php", $to . "/app/admin_routes.php");
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function destroy($id)
}

// Delete Admin Routes
if(LAHelper::laravel_ver() == 5.3) {
if(LAHelper::is_recent_laravel_version()) {
$file_admin_routes = base_path("/routes/admin_routes.php");
} else {
$file_admin_routes = base_path("/app/Http/admin_routes.php");
Expand Down
98 changes: 55 additions & 43 deletions src/Helpers/LAHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
class LAHelper
{

const RECENT_LARAVEL = 5.3;
/**
* Gives various names of Module in Object like label, table, model, controller, singular
*
Expand All @@ -36,7 +38,7 @@ public static function generateModuleNames($module_name, $icon)
$array = array();
$module_name = trim($module_name);
$module_name = str_replace(" ", "_", $module_name);

$array['module'] = ucfirst(str_plural($module_name));
$array['label'] = ucfirst(str_plural($module_name));
$array['table'] = strtolower(str_plural($module_name));
Expand All @@ -45,10 +47,10 @@ public static function generateModuleNames($module_name, $icon)
$array['controller'] = $array['module'] . "Controller";
$array['singular_l'] = strtolower(str_singular($module_name));
$array['singular_c'] = ucfirst(str_singular($module_name));

return (object)$array;
}

/**
* Get list of Database tables excluding LaraAdmin Context tables like
* backups, la_configs, la_menus, migrations, modules, module_fields, module_field_types
Expand Down Expand Up @@ -84,7 +86,7 @@ public static function getDBTables($remove_tables = [])
} else {
$tables = DB::select('SHOW TABLES');
}

$tables_out = array();
foreach($tables as $table) {
$table = (Array)$table;
Expand Down Expand Up @@ -112,15 +114,15 @@ public static function getDBTables($remove_tables = [])
$remove_tables = array_merge($remove_tables, $remove_tables2);
$remove_tables = array_unique($remove_tables);
$tables_out = array_diff($tables_out, $remove_tables);

$tables_out2 = array();
foreach($tables_out as $table) {
$tables_out2[$table] = $table;
}

return $tables_out2;
}

/**
* Get Array of All Modules
*
Expand All @@ -132,21 +134,21 @@ public static function getDBTables($remove_tables = [])
public static function getModuleNames($remove_modules = [])
{
$modules = Module::all();

$modules_out = array();
foreach($modules as $module) {
$modules_out[] = $module->name;
}
$modules_out = array_diff($modules_out, $remove_modules);

$modules_out2 = array();
foreach($modules_out as $module) {
$modules_out2[$module] = $module;
}

return $modules_out2;
}

/**
* Method to parse the dropdown, Multiselect, Taginput and radio values which are linked with
* either other tables via "@" e.g. "@employees" or string array of values
Expand Down Expand Up @@ -182,7 +184,7 @@ public static function parseValues($value)
}
return $valueOut;
}

/**
* Log method to log either in command line or in Log file depending on $type.
*
Expand All @@ -203,7 +205,7 @@ public static function log($type, $text, $commandObject)
Log::$type($text);
}
}

/**
* Method copies folder recursively into another
*
Expand All @@ -230,7 +232,7 @@ public static function recurse_copy($src, $dst)
}
closedir($dir);
}

/**
* Method deletes folder and its content
*
Expand All @@ -253,7 +255,7 @@ public static function recurse_delete($dir)
rmdir($dir);
}
}

/**
* Generate Random Password
*
Expand Down Expand Up @@ -283,7 +285,7 @@ public static function gen_password($chars_min = 6, $chars_max = 8, $use_upper_c
}
return $password;
}

/**
* Get url of image by using $upload_id
*
Expand All @@ -301,7 +303,7 @@ public static function img($upload_id)
return "";
}
}

/**
* Get Thumbnail image path of Uploaded image
*
Expand Down Expand Up @@ -355,7 +357,7 @@ public static function createThumbnail($filepath, $thumbpath, $thumbnail_width,
$imgt($new_image, $thumbpath);
return file_exists($thumbpath);
}

/**
* Print the menu editor view.
* This needs to be done recursively
Expand All @@ -367,25 +369,28 @@ public static function createThumbnail($filepath, $thumbpath, $thumbnail_width,
*/
public static function print_menu_editor($menu)
{

$editing = \Collective\Html\FormFacade::open(['route' => [config('laraadmin.adminRoute') . '.la_menus.destroy', $menu->id], 'method' => 'delete', 'style' => 'display:inline']);
$editing .= '<button class="btn btn-xs btn-danger pull-right"><i class="fa fa-times"></i></button>';
$editing .= \Collective\Html\FormFacade::close();

if($menu->type != "module") {
$info = (object)array();
$info->id = $menu->id;
$info->name = $menu->name;
$info->url = $menu->url;
$info->type = $menu->type;
$info->icon = $menu->icon;

$editing .= '<a class="editMenuBtn btn btn-xs btn-success pull-right" info=\'' . json_encode($info) . '\'><i class="fa fa-edit"></i></a>';
// dd($editing);
}
$str = '<li class="dd-item dd3-item" data-id="' . $menu->id . '">
<div class="dd-handle dd3-handle"></div>
<div class="dd3-content"><i class="fa ' . $menu->icon . '"></i> ' . $menu->name . ' ' . $editing . '</div>';

$childrens = \Dwij\Laraadmin\Models\Menu::where("parent", $menu->id)->orderBy('hierarchy', 'asc')->get();

if(count($childrens) > 0) {
$str .= '<ol class="dd-list">';
foreach($childrens as $children) {
Expand All @@ -394,9 +399,10 @@ public static function print_menu_editor($menu)
$str .= '</ol>';
}
$str .= '</li>';

return $str;
}

/**
* Print the sidebar menu view.
* This needs to be done recursively
Expand All @@ -420,9 +426,9 @@ public static function print_menu($menu, $active = false)
if($active) {
$active_str = 'class="active"';
}

$str = '<li' . $treeview . ' ' . $active_str . '><a href="' . url(config("laraadmin.adminRoute") . '/' . $menu->url) . '"><i class="fa ' . $menu->icon . '"></i> <span>' . LAHelper::real_module_name($menu->name) . '</span> ' . $subviewSign . '</a>';

if(count($childrens)) {
$str .= '<ul class="treeview-menu">';
foreach($childrens as $children) {
Expand All @@ -436,7 +442,7 @@ public static function print_menu($menu, $active = false)
$str .= '</li>';
return $str;
}

/**
* Print the top navbar menu view.
* This needs to be done recursively
Expand All @@ -450,7 +456,7 @@ public static function print_menu($menu, $active = false)
public static function print_menu_topnav($menu, $active = false)
{
$childrens = \Dwij\Laraadmin\Models\Menu::where("parent", $menu->id)->orderBy('hierarchy', 'asc')->get();

$treeview = "";
$treeview2 = "";
$subviewSign = "";
Expand All @@ -463,9 +469,9 @@ public static function print_menu_topnav($menu, $active = false)
if($active) {
$active_str = 'class="active"';
}

$str = '<li ' . $treeview . '' . $active_str . '><a ' . $treeview2 . ' href="' . url(config("laraadmin.adminRoute") . '/' . $menu->url) . '">' . LAHelper::real_module_name($menu->name) . $subviewSign . '</a>';

if(count($childrens)) {
$str .= '<ul class="dropdown-menu" role="menu">';
foreach($childrens as $children) {
Expand All @@ -476,8 +482,11 @@ public static function print_menu_topnav($menu, $active = false)
$str .= '</li>';
return $str;
}

/**
public static function is_recent_laravel_version()
{
return self::laravel_ver() >= self::RECENT_LARAVEL;
}
/**
* Get laravel version. very important in installation and handling Laravel 5.3 changes.
*
* LAHelper::laravel_ver()
Expand All @@ -487,19 +496,22 @@ public static function print_menu_topnav($menu, $active = false)
public static function laravel_ver()
{
$var = \App::VERSION();

if(starts_with($var, "5.2")) {
return 5.2;
} else if(starts_with($var, "5.3")) {
return 5.3;
} else if(substr_count($var, ".") == 3) {
} else if(starts_with($var, "5.4")) {
return 5.4;
}
else if(substr_count($var, ".") == 3) {
$var = substr($var, 0, strrpos($var, "."));
return $var . "-str";
} else {
return floatval($var);
}
}

/**
* Get real Module name by replacing underscores within name
*
Expand All @@ -511,7 +523,7 @@ public static function real_module_name($name)
$name = str_replace('_', ' ', $name);
return $name;
}

/**
* Get complete line within file by comparing passed substring $str
*
Expand All @@ -531,7 +543,7 @@ public static function getLineWithString($fileName, $str)
}
return -1;
}

/**
* Get complete line within given file contents by comparing passed substring $str
*
Expand All @@ -551,7 +563,7 @@ public static function getLineWithString2($content, $str)
}
return -1;
}

/**
* Method sets parameter in ".env" file as well as into php environment.
*
Expand All @@ -562,16 +574,16 @@ public static function getLineWithString2($content, $str)
*/
public static function setenv($param, $value)
{

$envfile = LAHelper::openFile('.env');
$line = LAHelper::getLineWithString('.env', $param . '=');
$envfile = str_replace($line, $param . "=" . $value . "\n", $envfile);
file_put_contents('.env', $envfile);

$_ENV[$param] = $value;
putenv($param . "=" . $value);
}

/**
* Get file contents
*
Expand All @@ -583,7 +595,7 @@ public static function openFile($from)
$md = file_get_contents($from);
return $md;
}

/**
* Delete file
*
Expand All @@ -597,7 +609,7 @@ public static function deleteFile($file_path)
unlink($file_path);
}
}

/**
* Get Migration file name by passing matching table name
*
Expand All @@ -619,7 +631,7 @@ public static function get_migration_file($file_name)
}
return "";
}

/**
* Check if passed array is associative
*
Expand All @@ -630,7 +642,7 @@ public static function is_assoc_array(array $array)
{
// Keys of the array
$keys = array_keys($array);

// If the array keys of the keys match the keys, then the array must
// not be associative (e.g. the keys array looked like {0:0, 1:1...}).
return array_keys($keys) !== $keys;
Expand Down
3 changes: 1 addition & 2 deletions src/Installs/app/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;

class Controller extends BaseController
{
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
Loading