PHP code example of munkh-altai / table-manager
1. Go to this page and download the library: Download munkh-altai/table-manager library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
munkh-altai / table-manager example snippets
composer
TableManager\TableManagerServiceProvider::class,
'TableManager' => TableManager\Facade\TableManager::class,
Route::get('/{slug}/', 'AdminController@TableManager');
Route::post('/{slug}/{action}', 'AdminController@TableManager');
use TableManager\TableManager;
public function TableProperties($slug, $action = 'index') {
if (!method_exists($this, $slug))
abort(503);
else
return $this->$slug($action);
}
public function users($action)
{
$tm = new TableManager();
$tm->viewName = 'table-manager';
$tm->table = 'users';
$tm->page_name = 'Хэрэглэгч';
$tm->identity_name = 'id';
$tm->grid_columns = [
'users.name',
'users.email',
'users.id'];
$tm->grid_default_order_by = 'users.id DESC';
$tm->formType = 'page';
$tm->created_at = 'created_at';
$tm->updated_at = 'updated_at';
$tm->where_condition = [];
$tm->grid_output_control = [
['column' => 'name', 'title' => 'Нэр', 'type' => '--text', 'fixed' => false],
['column' => 'email', 'title' => 'И-мэйл', 'type' => '--text', 'fixed' => false],
];
$tm->form_input_control = [
['column' => 'name', 'title' => 'Нэр', 'type' => '--text', 'value' => null, 'validate' => '
$tp->form_input_control = [
['column'=>'is_buleg', 'title'=>'Бүлэг эсэх', 'type'=>'--text', 'change_value'=>[
['value'=>0, 'text'=>'Үгүй'],
['value'=>1, 'text'=>'Тийм'],
]
],
];
$tp->permission = ['c'=>true, 'r'=>true, 'u'=>true, 'd'=>true];
$tp->before_delete = [
'controller'=>'App\Http\Controllers\AdminController',
'function'=>'beforeDeleteAanSalbar'
];
//exmample before delete function
public function beforeDeleteAanSalbar($id){
$userid = DB::table('aan')->select('user_id')->where('ID', '=', $id)->pluck('user_id');
DB::table('users')->where('id', '=', $userid)->delete();
}
$tp->form_input_control = [
['column'=>'is_baiguullaga', 'title'=>'Ажил олгогчийн төрөл', 'type'=>'--radio', 'value'=>0, 'choices'=>[
['value'=>0, 'text'=>'Аж ахуйн нэгж, байгууллага'],
['value'=>1, 'text'=>'Иргэн'],
], 'validate'=>'
$tp->before_insert = [
'controller'=>'App\Http\Controllers\AdminController',
'function'=>'beforeInsertUser',
'arguments'=>[]
];
//exmample before insert function
public function beforeInsertUser($data){
$insert_values = $data['insert_values'];
$user = [];
$pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 8);
$toMail = $insert_values['email'];
Mail::send('mail.register', ['password'=>$pass, 'email'=>$toMail], function($message) use ($toMail) {
$message->to($toMail);
$message->subject('Нэвтрэх нууц үг');
});
return ['password'=>bcrypt($pass)];
}
public function locales ($action){
$tp = new Tp();
$tp->viewName = 'admin._pages.options';
$tp->table = 'solar_locales';
$tp->page_name = 'Хэл';
$tp->identity_name = 'id';
$tp->grid_default_order_by = 'id DESC';
$tp->grid_columns = ['code', 'language', 'flag', 'id'];
$tp->grid_output_control = [
['column'=>'code', 'title'=>'Улсын код', 'type'=>'--text'],
['column'=>'language', 'title'=>'Хэл', 'type'=>'--text'],
['column'=>'flag', 'title'=>'Туг', 'type'=>'--text'],
];
$tp->form_input_control = [
['column'=>'code', 'title'=>'Улсын код', 'type'=>'--text', 'value'=>null, 'validate'=>'
function staticWords($action){
$tp = new Tp();
$tp->viewName = 'admin._pages.options';;
$tp->table = 'solar_static_words';
$tp->page_name = 'Статик үгсийн сан';
$tp->identity_name = 'id';
$tp->grid_default_order_by = 'id DESC';
$tp->grid_columns = ['key', 'translation', 'id'];
$tp->generateLocaleFile = true;
$tp->grid_output_control = [
['column' => 'key', 'title' => 'Түлхүүр үг', 'type' => '--text'],
['column' => 'translation', 'title' => 'Орчуулга', 'type' => '--text', 'translate' =>true],
];
$tp->form_input_control = [
['column' => 'key', 'title' => 'Түлхүүр үг', 'type' => '--text', 'value' => null, 'validate' => '
php artisan vendor:publish --tag=tm-config