/** * @param $request * * @return array */ private function parseData($request) { $role = $request->user()->role_id; $crudName = explode('.', $request->route()->getName())[1]; $crud = Crud::where('name', ucfirst($crudName))->firstOrFail(); return [$role, $crud]; }
/** * @param $request * * @return array */ private function parseData($request) { $role = $request->user()->role_id; $route = explode('.', $request->route()->getName()); $official = ['crud', 'users']; if (in_array($route[0], $official)) { return [$role, (object) ['roles' => config('quickadmin.defaultRole') . ',']]; } else { $crudName = $route[1]; } $crud = Crud::where('name', ucfirst($crudName))->firstOrFail(); return [$role, $crud]; }
/** * Build model relationships * @return string */ private function buildRelationships() { $cruds = Crud::all()->keyBy('id'); $used = []; $relationships = ''; foreach ($this->fields as $key => $field) { if (!in_array($field->title, $used) && $field->type == 'relationship') { $crud = $cruds[$field->relationship_id]; $relLine = ' public function $RELATIONSHIP$() { return $this->hasOne(\'App\\$RELATIONSHIP_MODEL$\', \'id\', \'$RELATIONSHIP$_id\'); }' . "\r\n\r\n"; $relLine = str_replace(['$RELATIONSHIP$', '$RELATIONSHIP_MODEL$'], [strtolower($crud->name), ucfirst(Str::camel($crud->name))], $relLine); $relationships .= $relLine; } } return $relationships; }
/** * Copy master template to resource/view */ public function copyMasterTemplate() { Crud::create(['name' => 'User', 'title' => 'User', 'is_crud' => 0]); $this->callSilent('vendor:publish', ['--tag' => ['quickadmin'], '--force' => true]); $this->info('Master template was transferred successfully'); }
/** * Insert new crud * * @param Request $request * * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function insert(Request $request) { $validation = Validator::make($request->all(), ['name' => 'required', 'title' => 'required', 'soft' => 'required']); if ($validation->fails()) { return redirect()->back()->withInput()->withErrors($validation); } // Get model names $cruds = Crud::all(); $models = []; foreach ($cruds as $crud) { $tableName = strtolower($crud->name); $models[$crud->id] = $tableName; } // Init QuickCache $cache = new QuickCache(); $cached = []; $cached['relationships'] = 0; $cached['files'] = 0; $cached['password'] = 0; $cached['date'] = 0; $cached['datetime'] = 0; $fields = []; foreach ($request->f_type as $index => $field) { $fields[$index] = ['type' => $field, 'title' => $request->f_title[$index], 'label' => $request->f_label[$index], 'helper' => $request->f_helper[$index], 'validation' => $request->f_validation[$index], 'value' => $request->f_value[$index], 'default' => $request->f_default[$index], 'relationship_id' => $request->has('f_relationship.' . $index) ? $request->f_relationship[$index] : '', 'relationship_name' => $request->has('f_relationship.' . $index) ? $models[$request->f_relationship[$index]] : '', 'relationship_field' => $request->has('f_relationship_field.' . $request->f_relationship[$index]) ? $request->f_relationship_field[$request->f_relationship[$index]] : '', 'texteditor' => $request->f_texteditor[$index], 'size' => $request->f_size[$index] * 1024, 'show' => $request->f_show[$index], 'dimension_h' => $request->f_dimension_h[$index], 'dimension_w' => $request->f_dimension_w[$index]]; if ($field == 'relationship') { $cached['relationships']++; } elseif ($field == 'file' || $field == 'photo') { $cached['files']++; } elseif ($field == 'password') { $cached['password']++; } elseif ($field == 'date') { $cached['date']++; } elseif ($field == 'datetime') { $cached['datetime']++; } } // dd($fields); $cached['fields'] = $fields; $cached['name'] = $request->name; $cached['soft_delete'] = $request->soft; $cache->put('fieldsinfo', $cached); // Create crud entry Crud::create(['position' => 0, 'icon' => $request->icon != '' ? $request->icon : 'fa-database', 'name' => $request->name, 'title' => $request->title, 'parent_id' => $request->parent_id != 0 ? $request->parent_id : null, 'roles' => '1']); // Create migrations $migrationBuilder = new MigrationBuilder(); $migrationBuilder->build(); // Create model $modelBuilder = new ModelBuilder(); $modelBuilder->build(); // Create request $requestBuilder = new RequestBuilder(); $requestBuilder->build(); // Create controller $controllerBuilder = new ControllerBuilder(); $controllerBuilder->build(); // Create views $viewsBuilder = new ViewsBuilder(); $viewsBuilder->build(); // Call migrations Artisan::call('migrate'); // Destroy our cache file $cache->destroy('fieldsinfo'); return redirect(config('quickadmin.route')); }
<?php /** * Package routing file specifies all of this package routes. */ use Illuminate\Support\Facades\View; use Laraveldaily\Quickadmin\Models\Crud; if (Schema::hasTable('cruds')) { $cruds = Crud::where('is_crud', 1)->orderBy('position')->get(); View::share('cruds', $cruds); if (!empty($cruds)) { Route::group(['middleware' => ['auth', 'role'], 'prefix' => config('quickadmin.route'), 'namespace' => 'App\\Http\\Controllers'], function () use($cruds) { foreach ($cruds as $crud) { resource(strtolower($crud->name), 'Admin\\' . ucfirst(camel_case($crud->name)) . 'Controller'); } }); } } Route::group(['namespace' => 'Laraveldaily\\Quickadmin\\Controllers', 'middleware' => 'auth'], function () { // Dashboard home page route Route::get(config('quickadmin.homeRoute'), 'QuickadminController@index'); Route::group(['middleware' => 'role'], function () { Route::get(config('quickadmin.route') . '/crud', ['as' => 'crud', 'uses' => 'QuickadminCrudController@create']); Route::post(config('quickadmin.route') . '/crud', ['as' => 'crud', 'uses' => 'QuickadminCrudController@insert']); }); }); // @todo move to default routes.php Route::group(['namespace' => 'App\\Http\\Controllers'], function () { // Point to App\Http\Controllers\UsersController as a resource Route::group(['middleware' => 'role'], function () { resource('users', 'UsersController');
<?php /** * Package routing file specifies all of this package routes. */ use Illuminate\Support\Facades\View; use Laraveldaily\Quickadmin\Models\Crud; if (Schema::hasTable('cruds')) { $cruds = Crud::with('children')->where('is_crud', 1)->orderBy('position')->get(); View::share('cruds', $cruds); if (!empty($cruds)) { Route::group(['middleware' => ['auth', 'role'], 'prefix' => config('quickadmin.route'), 'namespace' => 'App\\Http\\Controllers'], function () use($cruds) { foreach ($cruds as $crud) { post(strtolower($crud->name) . '/massDelete', ['as' => config('quickadmin.route') . '.' . strtolower($crud->name) . '.massDelete', 'uses' => 'Admin\\' . ucfirst(camel_case($crud->name)) . 'Controller@massDelete']); resource(strtolower($crud->name), 'Admin\\' . ucfirst(camel_case($crud->name)) . 'Controller'); } }); } } Route::group(['namespace' => 'Laraveldaily\\Quickadmin\\Controllers', 'middleware' => 'auth'], function () { // Dashboard home page route Route::get(config('quickadmin.homeRoute'), 'QuickadminController@index'); Route::group(['middleware' => 'role'], function () { Route::get(config('quickadmin.route') . '/crud', ['as' => 'crud', 'uses' => 'QuickadminCrudController@create']); Route::post(config('quickadmin.route') . '/crud', ['as' => 'crud', 'uses' => 'QuickadminCrudController@insert']); Route::get(config('quickadmin.route') . '/actions', ['as' => 'actions', 'uses' => 'UserActionsController@index']); Route::get(config('quickadmin.route') . '/actions/ajax', ['as' => 'actions.ajax', 'uses' => 'UserActionsController@table']); }); }); // @todo move to default routes.php Route::group(['namespace' => 'App\\Http\\Controllers'], function () {
/** * Build relationships for forms * @return string */ public function relationshipsBuilder() { if ($this->relationships == 0) { return ''; } else { $cruds = Crud::all()->keyBy('id'); $relationships = ''; $first = true; foreach ($this->fields as $field) { if ($field->type == 'relationship') { // Formatting fix if the relationship is not first if (!$first) { $relationships .= ' '; } $crud = $cruds[$field->relationship_id]; $relationships .= '$' . $field->relationship_name . ' = ' . ucfirst(Str::camel($crud->name)) . '::lists("' . $field->relationship_field . '", "id");' . "\r\n"; } } return $relationships; } }