/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request, Devis $devis, $table_id)
 {
     $table = Table::find($table_id);
     $table->fields()->create($request->all());
     Session::flash('flash_message', 'Field added!');
     return redirect()->back();
 }
 public function handle()
 {
     $script = '';
     foreach ($this->table->hasHasManyRelationList() as $relation) {
         $fromField = Field::find($relation['from_field_id']);
         $toModel = Table::find($relation['to_model_id']);
         $script .= $this->tab1 . 'public function ' . $relation['methodName'] . '(Request $request, ' . $this->table->model . ' $' . $this->table->variable . ')' . "\n";
         $script .= $this->tab1 . '{' . "\n";
         $script .= $this->tab2;
         $script .= '$' . $toModel->variablePlural . ' = $' . $this->table->variable . '->' . $relation['methodName'] . ';' . "\n";
         if ($toModel->hasBelongsToRelation()) {
             $script .= $this->tab2;
             $script .= '$' . $toModel->variablePlural . ' -> load(';
             foreach ($toModel->belongsToRelationList() as $relation) {
                 $script .= '\'' . $relation['methodName'] . '\', ';
             }
             $script = trim($script);
             $script = rtrim($script, ',');
             $script .= ');';
         }
         $script .= "\n";
         $script .= $this->tab2 . 'return response([\'data\' => $' . $toModel->variablePlural . ', \'status\' => \'success\', \'message\'=>\'\']);' . "\n" . "\n";
         $script .= $this->tab1 . '}' . "\n\n";
     }
     return $script;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $table = Table::find($id);
     $table->number = '';
     $table->save();
     $table->delete();
     return redirect()->back()->withSuccess('Tafel succesvol verwijderd.');
 }
Beispiel #4
0
 public function handle()
 {
     $script = '';
     /*
      **  create
      */
     $script .= $this->tab1 . 'public function create()' . "\n";
     $script .= $this->tab1 . '{' . "\n";
     // admin.client.create
     foreach ($this->relationship as $relation) {
         $table_ = Table::find($relation['to_model_id']);
         if (in_array($relation['laravel_name'], ['belongsTo', 'belongsToMany'])) {
             $foreignLabelList = $table_->fields()->where('is_on_foreign_label', 1);
             if ($foreignLabelList->count() == 1) {
                 $label = $foreignLabelList->first()->name;
                 $script .= $this->tab2 . '$' . $table_->variablePlural . '=' . $table_->model . '::lists("' . $label . '", "' . $table_->getPrimaries()->first()->name . '");' . "\n";
             }
             if ($foreignLabelList->count() > 1) {
                 $script .= $this->tab2 . '$' . $table_->variablePlural . '=' . $table_->model . '::select(\\DB::raw("CONCAT(';
                 $label = '';
                 foreach ($foreignLabelList->get() as $key => $foreignLabel) {
                     $label .= $foreignLabel->name;
                     if ($key + 1 != $foreignLabelList->count()) {
                         $label .= ", ' ', ";
                     }
                 }
                 $script .= $label . ') AS full_name, ' . $table_->getPrimaries()->first()->name . '"))->lists("full_name", "' . $table_->getPrimaries()->first()->name . '");' . "\n";
             } else {
                 if ($foreignLabelList->count() == 0) {
                     echo "<div style='color:white; background-color:red'>\n                            <h1>You have to specify a foreign_label for the table <a target='_blank' href='" . route('admin.devis.{devis}.tables.fields.create', [$this->devis->id, $table_->id]) . "'>{{$table_->name}}</a></h1>\n                        </div>";
                 }
             }
         }
     }
     $script .= $this->tab2 . "return View::make('" . $this->viewbasePath . ".create'";
     if (count($this->relationship) > 0) {
         $script .= ', compact([';
     }
     foreach ($this->relationship as $relation) {
         $table_ = Table::find($relation['to_model_id']);
         if (in_array($relation['laravel_name'], ['belongsTo', 'belongsToMany'])) {
             $script .= "'" . $table_->variablePlural . "',";
         }
     }
     $script = rtrim($script, ",");
     if (count($this->relationship) > 0) {
         $script .= '])';
     }
     $script .= ");" . "\n";
     $script .= $this->tab1 . '}' . "\n\n";
     return $script;
 }
 public function ManyComponents()
 {
     if ($this->table->hasHasManyRelation()) {
         foreach ($this->table->hasHasManyRelationList() as $relation) {
             $related_model = \App\Table::find($relation['to_model_id']);
             $componentName = $related_model->vueComponentName('list', $relation['methodName']);
             $path = $this->table->vueComponentRelativePathTo($related_model, 'list');
             $importScriptLine = 'import ' . $componentName . ' from \'' . $path . '\'';
             $methodName = $relation['methodName'];
             $this->ManyComponents->push(compact(['componentName', 'path', 'importScriptLine', 'related_model', 'methodName']));
         }
     }
 }
 public function closeOrder($tableId)
 {
     echo '<pre>';
     $table = Table::find($tableId);
     $client = $table->clients()->orderBy('entertime', 'DESC')->first();
     var_dump($table);
     $lastOrder = $client->orders()->where('endtime', NULL)->get();
     foreach ($lastOrder as $order) {
         $order->endtime = Carbon::now('Europe/Brussels');
         $order->save();
     }
     return 'ended';
 }
Beispiel #7
0
 public function getVariableList()
 {
     foreach ($this->relationship as $relation) {
         $table_ = Table::find($relation['to_model_id']);
         if (in_array($relation['laravel_name'], ['belongsTo', 'belongsToMany'])) {
             $this->viewsVariableList->push($table_);
         } else {
             if (in_array($relation['laravel_name'], ['hasMany'])) {
                 $related_table = Table::find($relation['to_model_id']);
                 foreach ($related_table->relationship() as $relation_2) {
                     if (in_array($relation_2['laravel_name'], ['belongsTo', 'belongsToMany'])) {
                         $related_table_2 = Table::find($relation_2['to_model_id']);
                         $this->viewsVariableList->push($related_table_2);
                     }
                 }
             }
         }
     }
     return $this;
 }
Beispiel #8
0
 public function handle()
 {
     // dd('<-----FORM------->',$this->devis, $this->table ,$this->view);
     $viewScript = "@extends('layouts." . $this->table->the_namespace->theme->name . "')" . "\n\n";
     $viewScript .= "@section('menu')" . "\n";
     $viewScript .= $this->tab1 . "@include('" . $this->devis->app_name . "." . $this->table->the_namespace->name . "/" . $this->menuFileNameUsed() . "')" . "\n";
     $viewScript .= "@endsection" . "\n";
     $viewScript .= "\n";
     $viewScript .= "@section('content')" . "\n";
     $viewScript .= '<h1>' . $this->title . '</h1>';
     foreach ($this->table->relationship() as $relation) {
         $table_ = Table::find($relation['to_model_id']);
         if ($relation['laravel_name'] == 'belongsTo') {
             $viewScript .= "\n";
             //$viewScript.='{{var_dump($'.$table_->variablePlural.')}}'."\n";
         }
     }
     $viewScript .= $this->tab1 . "@include('" . $this->table->viewPathInController() . ".form')" . "\n";
     $viewScript .= '@endsection';
     $this->createFile('../resources/views/' . $this->devis->app_name . '/' . $this->table->the_namespace->name . '/' . $this->table->model . '/' . $this->view . '.blade.php', $this->devis->app_name, $viewScript);
 }
 public function pull($id)
 {
     $table = Table::find($id);
     $url = $table->sheetsu_url;
     $client = new Client();
     $json = $client->get($url);
     $data = json_decode($json->getBody());
     $goto = '';
     switch ($table->name) {
         case 'users':
             $goto = $this->updateUsers($data->result);
             break;
         case 'posts':
             $goto = $this->updatePosts($data->result);
             break;
         case 'user_friend_pivot':
             $goto = $this->updateFriends($data->result);
             break;
     }
     return redirect($goto);
 }
 public function handle()
 {
     $script = '<?php' . "\n\n";
     $script .= "Route::group(['prefix'=>'api/" . $this->devis->app_name . "'], function () {" . "\n";
     foreach ($this->devis->tables as $table) {
         if ($table->model != '') {
             $script .= "\t" . 'Route::resource("' . $table->name . '", "' . $table->controllerRouteApiClass() . '");' . "\n";
         }
         if ($table->hasHasBelongsToRelation()) {
             $script .= "\t" . 'Route::get("' . $table->name . '/{' . $table->variable . '}/showWithRelations", "' . $table->controllerRouteApiClass() . '@showWithRelations");' . "\n";
         }
         foreach ($table->hasHasManyRelationList() as $relation) {
             // var_dump($relation);
             $fromField = Field::find($relation['from_field_id']);
             $fromModel = Table::find($relation['model_id']);
             $toModel = Table::find($relation['to_model_id']);
             $script .= "\t\t" . 'Route::get("' . $table->name . '/{' . $fromModel->variable . '}/' . $relation['methodName'] . '", "' . $table->controllerRouteApiClass() . '@' . $relation['methodName'] . '");' . "\n";
         }
         if ($this->getSpecialVueComponentList($table)) {
             $script .= "\n\n";
             $script .= "//get Special Vue Component";
             $script .= "\n";
             foreach ($this->getSpecialVueComponentList($table) as $specialView) {
                 $specialView = '\\Organit\\bootstrapping\\Vue\\MiddlesepcialComponentViews\\' . $this->devis->app_name . '\\' . $specialView;
                 $script .= "\t\t" . (new $specialView($this->devis, $table))->CoreSpecialCompo()->RoutePHPLine();
                 $script .= "\n";
             }
         }
         $script .= "\n\n";
     }
     $script .= "});";
     $this->createFile('../app/Http/' . $this->devis->app_name . '_api.php', $this->devis->app_name, $script);
     echo "<h1>-->Copier dans app\\Providers\\RouteServiceProvider.php</h1>";
     echo "<pre>";
     echo "\n        require app_path('Http/" . $this->devis->app_name . "_routes.php');\n        require app_path('Http/" . $this->devis->app_name . "_api.php');";
     echo "</pre>";
     echo '<a href="/' . $this->devis->app_name . '">Test Route</a>';
 }
 public function sortMigrationArray()
 {
     foreach ($this->devis->tables as $table) {
         # get list $requireTables //ok
         // $table = Table::find($table_id);
         echo $table->name;
         $requireTables = [];
         foreach ($table->fields as $field) {
             foreach ($field->relations as $relation) {
                 if (in_array($relation->pivot->laravel_name, ['belongsToMany', 'morphedByMany', 'morphToMany'])) {
                     $related_table = \App\Table::find($relation->pivot->to_model);
                     $requireTables[] = $related_table->id;
                 }
                 if (in_array($relation->pivot->laravel_name, ['belongsTo'])) {
                     $related_table = Field::find($relation->pivot->to_field_id)->table;
                     $requireTables[] = $related_table->id;
                 }
             }
         }
         var_dump($requireTables);
         # get the current position of the table $currentindex
         //    dd($this->migrationsArray->search('1'));
         var_dump($this->migrationsArray);
         foreach ($requireTables as $key => $requireTable) {
             #remove the requireTables from array
             $index = array_search($requireTable, $this->migrationsArray);
             unset($this->migrationsArray[$index]);
             var_dump($currentTableIndex);
             //place le require fields before the $currentindex
             $this->insert_before($this->migrationsArray, $currentTableIndex, array($index => $requireTable));
         }
         var_dump($this->migrationsArray);
         //die('++-++-');
         // }
     }
 }
Beispiel #12
0
                                                @if(isset($relation->pivot->laravel_name) && in_array($relation->pivot->laravel_name , ['hasMany', 'MorphToMany' ]))
                                                    <?php 
$related_table = \App\Field::find($relation->pivot->to_field_id)->table()->first();
?>
                                                    <a href="{{route('admin.devis.{devis}.admin.table.edit', [$devis->id, $related_table->id])}}"><h3>{{$related_table->name }}</h3></a>
                                                    {{$relation->pivot->to_field_id}} -
                                                    {{\App\Field::find($relation->pivot->to_field_id)->name }} <span style="color:#ccc">(<i>{{App\Field::find($relation->pivot->to_field_id)->type->name }}</i>)</span>


                                                    <b>{{\App\Field::find($relation->pivot->to_field_id)->table->first()->name }}</b><br>
                                                    <i>{{\App\Field::find($relation->pivot->to_field_id)->name }}</i>
                                                @elseif($relation->pivot->laravel_name == 'belongsToMany')
                                                    <?php 
// dd(\App\Field::find($relation->pivot->on_field_id)->table->get());
$related_table = \App\Table::find($relation->pivot->to_model);
$related_field = \App\Field::find($relation->pivot->on_field_id);
?>
                                                    <a href="{{route('admin.devis.{devis}.admin.table.edit', [$devis->id, $related_table->id])}}"><h3>{{$related_table->name }}</h3></a>
                                                    {{-- {{dd($related_fields->)}} --}}
                                                    {{$related_field->id}} -
                                                    {{$related_field->name }} <span style="color:#ccc">(<i>{{$related_field->type->name }}</i>)</span>

                                                @endif
                                            </div>
                                            <div class="col-md-1">

                                                {!! Form::open([
                                                    'method'=>'DELETE',
                                                    'route' => ['admin.devis.{devis}.relation.delete', $devis->id,$relation->pivot->from_field_id ,$relation->pivot->to_field_id],
                                                    'style' => 'display:inline'
Beispiel #13
0
 public function handle()
 {
     foreach ($this->devis->tables()->where('model', '<>', '')->get() as $a => $table) {
         // echo '<h5>&nbsp;&nbsp;&nbsp;&nbsp;<i style="color:green">></i> Preparing files for table <u style="color:#15c">';
         // echo $table->name;
         // echo '</u></h5>';
         $script = '<?php' . "\n\n";
         // dd($table->modelNamespace());
         $script .= 'namespace ' . $table->modelNamespace() . ';' . "\n\n";
         $script .= 'use Illuminate\\Database\\Eloquent\\Model;' . "\n\n";
         $useList = [];
         // if($table->name == 'users'){
         foreach ($table->fields as $field) {
             // echo $field->name.'<br>';
             foreach ($field->relations as $relation) {
                 if (in_array($relation->pivot->laravel_name, ['belongsToMany', 'morphedByMany', 'morphToMany'])) {
                     $related_table = \App\Table::find($relation->pivot->to_model);
                 }
                 if (in_array($relation->pivot->laravel_name, ['hasMany', 'belongsTo'])) {
                     $related_table = Field::find($relation->pivot->to_field_id)->table;
                 }
                 $useList[] = $related_table->modelNamespaceClass();
                 // echo $relation->table->modelNamespaceClass();
             }
         }
         // dd('class=>',$table->modelNamespaceClass(), 'uses=>', $useList);
         // }
         // var_dump($this->renderUsesStatements($useList));
         $script .= $this->renderUsesStatements($useList);
         $script .= 'class ' . $table->model . ' extends Model' . "\n";
         $script .= '{' . "\n\n";
         $script .= $this->tab1 . 'protected $guarded = [];' . "\n";
         $script .= $this->tab1 . 'protected $table = "' . $table->tablename . '";' . "\n";
         $dateFields = $table->fields->whereIn('field_type_id', [5, 6, 14]);
         // dd($dateFields->count());
         if ($dateFields->count() > 0) {
             $script .= $this->tab1 . 'protected $dates = [';
             foreach ($dateFields as $dateField) {
                 $script .= '\'' . $dateField->name . '\'' . ',';
             }
             $script = rtrim($script, ',');
             $script .= '];' . "\n";
         }
         //var_dump($table->getPrimaries()->count() > 0);
         if ($table->getPrimaries()->count() > 0) {
             if ($table->getPrimaries()->first()->name != 'id' && $table->getPrimaries()->count() == 1) {
                 $script .= $this->tab1 . 'protected $primaryKey = "' . $table->getPrimaries()->first()->name . '";' . "\n";
             }
         }
         $script .= "\n";
         foreach ($table->relationship() as $relation) {
             if ($relation['laravel_name'] == 'belongsTo') {
                 $defaultFieldName = strtolower(snake_case($relation['to_model'])) . '_id';
                 $script .= $this->tab1 . 'public function ' . $relation['methodName'] . '() {' . "\n";
                 $script .= $this->tab2 . 'return $this->belongsTo(' . $relation['to_model'] . '::class';
                 $showfirstArg = false;
                 if ($relation['from_field'] != $defaultFieldName) {
                     $showfirstArg = true;
                     $script .= ', "' . $relation['from_field'] . '"';
                 }
                 if ($relation['to_field'] != 'id') {
                     if (!$showfirstArg) {
                         $script .= ', "' . $relation['from_field'] . '"';
                     }
                     $script .= ', "' . $relation['to_field'] . '"';
                 }
                 $script .= ');' . "\n";
                 $script .= $this->tab1 . '}' . "\n";
             }
             if ($relation['laravel_name'] == 'hasMany') {
                 $defaultFieldName = strtolower(snake_case($relation['model'])) . '_id';
                 $script .= $this->tab1 . 'public function ' . $relation['methodName'] . '() {' . "\n";
                 $script .= $this->tab2 . 'return $this->hasMany(' . $relation['to_model'] . '::class';
                 $showfirstArg = false;
                 if ($relation['to_field'] != $defaultFieldName) {
                     $showfirstArg = true;
                     $script .= ', "' . $relation['to_field'] . '"';
                 }
                 if ($relation['from_field'] != 'id') {
                     if (!$showfirstArg) {
                         $script .= ', "' . $relation['to_field'] . '"';
                     }
                     $script .= ', "' . $relation['from_field'] . '"';
                 }
                 $script .= ');' . "\n";
                 $script .= $this->tab1 . '}' . "\n";
             }
             if ($relation['laravel_name'] == 'belongsToMany') {
                 /*
                  **  defaultPivotTableName
                  */
                 $array = array($relation['model'], $relation['to_model']);
                 sort($array);
                 $defaultPivotTableName = $this->devis->prefix() . strtolower($array[0] . '_' . $array[1]);
                 //end defaultPivotTableName
                 $script .= $this->tab1 . 'public function ' . $relation['methodName'] . '() {' . "\n";
                 //$relation->pivot->to_field_id = Field::find($relation->pivot->to_field_id)->name;
                 $script .= $this->tab2 . 'return $this->belongsToMany(' . $relation['to_model'] . '::class';
                 // $prefixNull=false;
                 // if ($this->devis->prefix() == '') {
                 //     $prefixNull=true;
                 //     // $script.=', "'.$this->devis->prefix().$relation['pivot_table'].'"';
                 // }else{
                 //     $prefixNull=false;
                 //
                 // }
                 $prefixNull = false;
                 if ($this->devis->prefix() == '') {
                     $prefixNull = true;
                 }
                 if ($this->devis->prefix() . $relation['pivot_table'] != $defaultPivotTableName || !$prefixNull) {
                     $script .= ', "' . $this->devis->prefix() . $relation['pivot_table'] . '"';
                 }
                 $script .= ');' . "\n";
                 $script .= $this->tab1 . '}' . "\n";
             }
         }
         $script .= "\n\n";
         /*
          **  specials methods fom the database class methods
          */
         foreach ($table->methods as $method) {
             // if ($method->isValidPHP()) {
             $script .= $this->tab1 . 'public function ' . $method->name . ' () {' . "\n";
             $script .= $this->tab2 . $method->content . "\n";
             $script .= $this->tab1 . "}\n\n";
             // }
         }
         $script .= "\n\n";
         $script .= '}' . "\n\n";
         // $script='';
         // echo "------>";
         // var_dump('../app/Models/'.$this->devis->app_name.'/'.$table->the_namespace->name.'/'.$table->model.'.php',$this->devis->app_name,$script);
         $this->createFile('../app/Models/' . $this->devis->app_name . '/' . $table->the_namespace->name . '/' . $table->model . '.php', $this->devis->app_name, $script, true);
         // die('++');
         //dd('123');
         // if ($table->name == 'users') {
         //     dd($script);
         // }
     }
     //dd('stop script model');
 }
Beispiel #14
0
 public function putGuestBackToDistribution($id)
 {
     $guest = Guest::find($id);
     $currentQue = Que::where('guest_id', $id)->limit(1)->orderBy('the_time')->first();
     $previousTable = Table::find(GuestRoute::where('guest_id', $id)->where('position_id', 2)->limit(1)->orderBy('the_time', 'desc')->first()->table_id);
     $guest = Guest::find($id);
     $guest->is_inside = 1;
     $guest->status = 'after test drive';
     $guest->save();
     $guestRoute = new GuestRoute();
     $guestRoute->guest_id = $id;
     $guestRoute->position_id = 2;
     $guestRoute->branche_id = $previousTable->branche_id;
     $guestRoute->save();
     $previousTable->current_que = $previousTable->current_que + 1;
     $previousTable->guests_count = $previousTable->guests_count + 1;
     $previousTable->save();
     $numberOfQue = count(Que::where('table_id', $previousTable->id)->get());
     if (intval($numberOfQue) > 2) {
         $lastTwo = Que::where('table_id', $previousTable->id)->limit(3)->orderBy('the_time', 'desc')->get();
         $the_time = Carbon::parse($lastTwo[2]->the_time)->addSecond();
     } else {
         $the_time = Carbon::now()->addMinutes(5);
     }
     $currentQue->the_time = $the_time;
     $currentQue->table_id = $previousTable->id;
     $currentQue->save();
     return redirect()->back();
 }
Beispiel #15
0
 public function handle()
 {
     $script = '';
     //$script.= "{{ $".$this->relation['to_model']." }} "."\n";
     $related_table = Table::find($this->relation['to_model_id']);
     $basePath = $related_table->devis->app_name . '.' . $related_table->the_namespace->name . "." . $related_table->variable;
     if ($related_table->the_namespace->name == 'Web') {
         $basePath = $related_table->devis->app_name . "." . $related_table->variable;
     }
     $primary = '';
     if ($related_table->getPrimaries()->first()) {
         $primary = $related_table->getPrimaries()->first()->name;
     } else {
         $script .= "\n            <div class='alert alert-error'>Pas de primary yey sur cette table - - les liens edt et create ne fonctionne pas</div>\n            ";
     }
     // $script.= "
     //     <h1>Liste</h1>
     //     <a href='{{ route('".$basePath.".create') }}' class='btn btn-success btn-sm'><i class='fa fa-plus'></i> Create a ".$related_table->model."</a>
     // "."\n\n";
     $script .= "\n        <!-- Button trigger modal -->\n        <button type='button' class='btn btn-success  btn-sm' data-toggle='modal' data-target='#Modal_" . $this->relation['methodName'] . "'>\n         <i class='fa fa-plus'></i> Add a " . $related_table->model . "\n        </button>" . "\n\n";
     $script .= "\n        <div class='table-responsive'>\n         <table class='table table-striped table-bordered table-hover dataTables-example' data-toggle='table' data-search='true' data-show-columns='true' data-pagination='true' data-height='750'>\n          <thead>\n            <tr>\n                <th>Actions</th>";
     foreach ($related_table->fields()->where('is_on_index_view', 1)->orderBy('order', 'asc')->get() as $field) {
         $script .= "\n                    <th>" . $field->label . "</th>";
     }
     $script .= "\n            </tr>\n        </thead>\n        <tbody>\n            @forelse(\$" . $this->table->variable . "->" . $this->relation['methodName'] . " as \$" . $related_table->variable . ")\n        <tr>\n                    <td>\n                        <a href='{{ route('" . $basePath . ".edit', [\$" . $related_table->variable . "->" . $primary . "]) }}'><i class='fa fa-edit'></i></a>\n                        {!! Form::open([\n                            'method'=>'DELETE',\n                            'route' => ['" . $basePath . ".destroy', \$" . $related_table->variable . "->" . $primary . "],\n                            'style' => 'display:inline'\n                        ]) !!}\n                            {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs', 'onclick'=>'return confirm()']) !!}\n                        {!! Form::close() !!}\n                    </td>\n        ";
     foreach ($related_table->fields()->where('is_on_index_view', 1)->orderBy('order', 'asc')->get() as $field) {
         $hasBelongsToRelation = false;
         foreach ($field->relations()->get() as $key => $relation) {
             if (in_array($relation->pivot->laravel_name, ['belongsTo'])) {
                 $hasBelongsToRelation = true;
                 $fromField = Field::find($relation->pivot->from_field_id);
                 $toField = Field::find($relation->pivot->to_field_id);
                 $toModel = $toField->table;
                 $defaultFieldName = strtolower(snake_case($toModel->model)) . '_id';
                 if ($fromField->name == $defaultFieldName) {
                     if ($toModel->variable == 'update') {
                         $functionNamne = 'updat';
                     } else {
                         $functionNamne = $toModel->variable;
                     }
                 } else {
                     $functionNamne = camel_case($fromField->name);
                 }
                 $script .= "<td>";
                 foreach ($toModel->fields()->where('is_on_foreign_label', 1)->get() as $fieldLabel) {
                     $script .= "{{ \$" . $related_table->variable . "->" . $functionNamne . "->" . $fieldLabel->name . "}} ";
                 }
                 $script .= "</td> " . "\n";
             }
         }
         if (!$hasBelongsToRelation) {
             if ($field->type->name == 'text') {
                 $script .= "<td>{{ str_limit(\$" . $related_table->variable . "->" . $field->name . ", 7)}}</td> " . "\n";
             } else {
                 $script .= "<td>{{ \$" . $related_table->variable . "->" . $field->name . "}}</td> " . "\n";
             }
         }
     }
     $script .= "\n        </tr>\n            @empty\n                    <tr><td>No data yet ...</td><tr>\n            @endforelse\n            </tbody>\n        </table>\n        </div>\n\n\n\n\n\n        <div class='modal fade' id='Modal_" . $this->relation['methodName'] . "' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'>\n          <div class='modal-dialog modal-lg' role='document'>\n            <div class='modal-content'>\n              <div class='modal-header'>\n                <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>\n                <h4 class='modal-title' id='myModalLabel'>Add a " . $related_table->model . "</h4>\n              </div>\n              <div class='modal-body'>\n\n                @include('" . $related_table->viewPathInController() . ".form', [ 'foreign_key' => '" . $this->relation['to_field'] . "', '" . $this->relation['to_field'] . "' => \$" . $this->table->variable . ", 'primary'=>'" . $related_table->getPrimaries()->first()->name . "', 'form_name'=>'" . $relation['methodName'] . "' ])\n\n              </div>\n              <div class='modal-footer'>\n                <button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>\n                <!--<button type='button' class='btn btn-primary'>Save changes</button>-->\n              </div>\n            </div>\n          </div>\n        </div>\n\n\n\n\n\n        ";
     return $script;
 }
 public function constructRouterVue2(Table $from_Table, $chaine_cumul = '', $chaine_edit = '', $chaine_list = '', $loop = 0)
 {
     //var_dump($loop);
     $chaine_cumul .= $from_Table->name . '/';
     $pieces = explode('/', $chaine_cumul);
     end($pieces);
     $avantDernier = prev($pieces);
     $table = Table::where('name', $avantDernier)->first();
     $id = ':id_' . $table->variable;
     echo "<h2>__________________________________________________________________________________________________________________________________________________________</h2>";
     var_dump($pieces);
     $chaine_edit = '';
     foreach ($pieces as $piece) {
         $table = Table::where('name', $piece)->first();
         if ($table) {
             $chaine_edit .= $piece . '/:id_' . $table->variable . '/';
         }
     }
     $chaine_list .= rtrim($chaine_edit, '/:id_' . $from_Table->variable . '/');
     //put thre keys
     // $chaine_edit.=$this->primary().'/';
     // $chaine_cumul.=$this->name.'/';
     foreach ($from_Table->hasHasManyRelationList() as $relation) {
         // var_dump($relation);
         $toTable = Table::find($relation['to_model_id']);
         //var_dump(rtrim($chaine_edit, '/'));
         //var_dump(rtrim($chaine_list, '/'));
         $this->constructRouterVue2($toTable, $chaine_cumul, $chaine_edit, $chaine_list, $loop++);
     }
     //var_dump(rtrim($chaine_edit, '/'));
     $chaine_list = rtrim($chaine_list, '/');
     $chaine_edit = rtrim($chaine_edit, '/');
     var_dump('------------chaine_edit');
     var_dump($chaine_edit);
     /*
             $toComponentTable = strrchr($chaine_list, '/');
             if (!$toComponentTable) {
                 echo ">>";
                 $toComponentTable=$chaine_list;
             }*/
     $toComponentTable = $avantDernier;
     echo "--->";
     var_dump($toComponentTable);
     echo "<---";
     echo "<h2>EDITION</h2>";
     /*
      **  EDITION
      */
     $table = Table::where('name', $toComponentTable)->first();
     if ($table) {
         $edit = new CreateEditComponent($this->devis, $table);
         $path = $edit->getPath();
     } else {
         echo "la table {$toComponentTable} non trouvee !!";
         $toComponentTable = $chaine_list;
         $table = Table::where('name', $toComponentTable)->first();
         $path = '';
         if ($table) {
             $list = new CreateEditComponent($this->devis, $table);
             $path = $list->getPath();
         }
     }
     $edition = $this->RouterVue[] = ['type' => 'edit', 'route' => $chaine_edit, 'to_component' => $toComponentTable, 'path' => $path];
     //var_dump($this->RouterVue);
     var_dump($edition);
     /*
      **  list
      */
     echo "<h2>LIST</h2>";
     //var_dump($chaine_list);
     $route = '';
     var_dump('edition[route]');
     var_dump($edition['route']);
     //$route = strrchr($edition['route'], '/')
     // $route=substr($edition['route'], 0, strpos($edition['route'], '/'));//remove everything after /
     $route = substr($edition['route'], 0, strrpos($edition['route'], '/'));
     //remove everything after /
     //  var_dump('route for list');
     //  var_dump($route);
     $table = Table::where('name', $toComponentTable)->first();
     if ($table) {
         $edit = new CreateListComponent($this->devis, $table);
         $path = $edit->getPath();
     } else {
         $toComponentTable = $chaine_list;
         $table = Table::where('name', $toComponentTable)->first();
         $path;
         if ($table) {
             $list = new CreateListComponent($this->devis, $table);
             $path = $list->getPath();
         }
     }
     $list = $this->RouterVue[] = ['type' => 'list', 'route' => $route, 'to_component' => $toComponentTable, 'path' => $path];
     var_dump($list);
     /*
      **  create
      */
     echo "<h2>FORM</h2>";
     $route = $list['route'] . '/create';
     //remove everything after /
     $table = Table::where('name', $toComponentTable)->first();
     if ($table) {
         $edit = new CreateFormComponent($this->devis, $table);
         $path = $edit->getPath();
     } else {
         $toComponentTable = $chaine_list;
         $table = Table::where('name', $toComponentTable)->first();
         $path = '';
         if ($table) {
             $list = new CreateFormComponent($this->devis, $table);
             $path = $list->getPath();
         }
     }
     $form = $this->RouterVue[] = ['type' => 'create', 'route' => $route, 'to_component' => $toComponentTable, 'path' => $path];
     var_dump($form);
     /*
             ** Ajout des component specifiques
     
             if ($this->getSpecialVueComponentList($this->table)){
                 foreach ($this->getSpecialVueComponentList($this->table) as $specialView) {
                     $componentName = $this->table->vueComponentName('', $specialView);
                     //$path = $this->table->vueComponentRelativePathTo($this->table, $specialView);
                     $tag = '<'.$this->table->VueTag('',$specialView ).' :'.$this->table->variable.'="object"></'.$this->table->VueTag('',$specialView ).'>';
     
                     //var_dump($editList);
                     //si la fin du liste == model concerné dans le specialcompo
                     //dd($edition['to_component'], $this->table->name);
     
     
     
     
                     // $file =  strrchr($path, '/');
                     // $file = trim($file, '/');
                     // $file = trim($file, '.php');
     
                     //on les execute pour trouver les namespaces
                     $vueClass =  '\Organit\bootstrapping\Vue\MiddlesepcialComponentViews\\'.$this->devis->app_name.'\\'.$specialView;
                 //     dd(
                 //     (new $vueClass($this->devis,$table))->CoreSpecialCompo()->model()
                 //     ,
                 //     (new \Organit\bootstrapping\Vue\MiddlesepcialComponentViews\Middle\BankAccount($this->devis,$table))->CoreSpecialCompo()->model()
                 // );
     
                 //recuperer la liste des table qui on des speciaux compo
                 $list_qq=[];
                 foreach ($this->devis->tables as $_table ) {
                     if ($_table == 'vehicles') {
                         dd($this->getSpecialVueComponentList($_table));
                         # code...
                     }
                     $list_qq[] =  $this->getSpecialVueComponentList($_table);
                 }
                 //dd($list_qq);
                 var_dump('********');
                 var_dump($vueClass);
                     $model = (new $vueClass($this->devis,$this->table))->CoreSpecialCompo()->model();
                     $related_table = Table::where('model', $model)->first();
                     if ($related_table) {
                         //if ($edition['to_component'] == $related_table->name) {
                             $this->RouterVue[]=[
                                 'type' => 'secial',
                                 'route' => $edition['route'].'/get_'.$componentName,
                                 'to_component' => $componentName,
                                 'path' => $edition['path'].'/'.$componentName,
                                 'tag' => $tag
                             ];
                         //}
                         # code...
                     }
     
     
     
     
                 }
             }
     */
     // var_dump(rtrim($chaine_cumul, '/'));
     // if (isset($toTable)) {
     //Table::constructRouterVue($table, $chaine_cumul,  $chaine_edit, $chaine_list, $loop++);
     # code...
     // }
 }
 public function delete($id)
 {
     Table::find($id)->delete();
     return redirect('table');
 }
    public function handle()
    {
        $script = '
        <style>
        .spacer{
            height: 50px;
            display: block;
        }
        </style>


        <template >
        <!--<pre>{{object | json}}</pre>-->


            <h1>' . $this->table->model . ' Form</h1>

            <div v-if="loading">
                <ui-preloader  :show="true"></ui-preloader>
            </div>

            <div class="row" v-show="!loading">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">


                        <!--<div class="row" v-if="mode==\'update\'">
                            <div class="col-md-12">
                                <div class="pull-right"><a @click="deleteObject(object)"> Detete</a></div>
                            </div>
                        </div>-->
                    </div>
                    <div class="ibox-content">

          <validator name="validation1">
            <form novalidate class="form-horizontal form-label-left">';
        foreach ($this->table->fields()->orderBy('order', 'asc')->get() as $field) {
            if ($field->is_incrementable || in_array($field->name, ['created_at', 'updated_at', 'updated_by'])) {
                continue;
            }
            //v-if="\''.$field->name.'\'=!label"
            $script .= '

                        <div >
                            ' . $this->VueformType($field) . '
                         </div>


                          ';
            //<!--<div v-else>
            //  <input type="text" :name="label" :value="value">
            // </div>-->
        }
        $script .= '

                <div class="col-sm-12">
                    <!--<button @click="cancel"  class="btn btn-default pull-right">Cancel</button>-->
                    <!--<button v-if="mode==\'update\'" @click.prevent="deleteObject(object)"  class="btn btn-danger pull-left">Delete</button>-->
                    <ui-icon-button v-if="mode==\'update\'" icon="delete" @click.prevent="deleteObject(object)" tooltip="Delete" type="normal" color="danger" class="pull-left" ></ui-icon-button>


                    <button @click.prevent="submit(object)" class="btn btn-primary pull-right" :disabled="$validation1.invalid';
        // foreach ($this->table->relationship() as $relation)  {
        //     if (in_array($relation['laravel_name'], ['belongsTo'])) {
        //         $fromField = Field::find($relation['from_field_id']);
        //         if ($fromField->isRequired()) {
        //             $script.=' && !object.'.$fromField->name;
        //         }
        //     }
        // }
        $script .= ' ">
                        <b v-if="mode==\'create\'">Create</b>
                        <b v-if="mode==\'update\'">Update</b>
                         ' . $this->table->model . ' <i class="fa fa-spin fa-spinner" v-show="sending"></i>
                     </button>

                </div>

            </form>
          </validator>


                    </div>
                </div>
            </div>
        </div>


        </template>





        <script>

        // import modal from \'../../snippets/modal.vue\'; ' . "\n";
        $components = [];
        foreach ($this->table->relationship() as $relation) {
            if (in_array($relation['laravel_name'], ['belongsTo']) && !in_array($relation['to_model_id'], $components)) {
                $script .= '';
                $related_model = \App\Table::find($relation['to_model_id']);
                $components[] = $relation['to_model_id'];
                $script .= 'import ' . $related_model->vueComponentName('form') . ' from \'' . $this->table->vueComponentRelativePathTo($related_model, 'form') . '\'' . "\n";
            }
        }
        $script .= '




        export default {
            components: { ';
        $components = [];
        foreach ($this->table->relationship() as $relation) {
            if (in_array($relation['laravel_name'], ['belongsTo']) && !in_array($relation['to_model_id'], $components)) {
                $script .= '';
                $related_model = \App\Table::find($relation['to_model_id']);
                $components[] = $relation['to_model_id'];
                $script .= $this->tab4 . $related_model->vueComponentName('form') . ',' . "\n";
            }
        }
        $script .= '
            },

            props :{
                forceMode : {
        				required: false,
        				type:String,
                },
                createdObject : {
        				required: false,
        				type:Object,
                },
                // label : {
        		// 		required: false,
        		// 		type:String,
                // },
                // value : {
        		// 		required: false,
        		// 		type:String,
                // }


            },


            ready () {
                for (label in this.$route.params) {
                    //console.log(label + \' : \' + this.$route.params[label]);

                    ';
        //get the list of the forign
        foreach ($this->table->getForeignFieldList() as $field) {
            $script .= '
                            if (label == \'' . $field->name . '\') {
                                var elem = document.querySelector(".' . $field->name . '"); // detruit le field dont on a la valeur
                                elem.parentNode.removeChild(elem);
                                this.object.' . $field->name . '=this.$route.params[label] //pre fill the form with the data
                            }
                        ';
        }
        $script .= '

                }

                ';
        $script .= 'this.loading=true' . "\n";
        if ($this->table->hasBelongsToRelation()) {
            foreach ($this->table->belongsToRelationList() as $relation) {
                $related_model = \App\Table::find($relation['to_model_id']);
                //$components[] = $relation['to_model_id'];
                $script .= 'this.fetch' . $related_model->model . '()' . "\n";
            }
        } else {
            $script .= 'this.fetchObject()' . "\n";
        }
        // foreach ($this->table->relationship() as $relation) {
        //     if (in_array($relation['laravel_name'],['belongsTo']) && ! in_array($relation['to_model_id'], $components)){
        //         $script.='';
        //         $related_model = \App\Table::find($relation['to_model_id']);
        //         $components[] = $relation['to_model_id'];
        //
        //         $script.='this.fetch'.$related_model->model.'()'."\n";
        //     }
        // }
        $script .= '
                // if (this.mode == \'update\') {
                //     this.loading=true
                //     this.fetchObject()
                // }




            },
            watch: {
                ';
        $components = [];
        foreach ($this->table->relationship() as $relation) {
            if (in_array($relation['laravel_name'], ['belongsTo']) && !in_array($relation['to_model_id'], $components)) {
                $related_model = \App\Table::find($relation['to_model_id']);
                $components[] = $relation['to_model_id'];
                $script .= '
                \'created' . $related_model->model . '\' :function (val, oldVal) {
                    this.object.' . $relation['from_field'] . '=this.created' . $related_model->model . '.' . $related_model->primary() . '
                },';
            }
        }
        if ($this->table->hasBelongsToRelation()) {
            $script .= '
                    \'EverythingLoaded\': function (val, oldVal) { //#vtest#
                        if(this.mode == \'update\') {
                            if (val) {
                                this.fetchObject()
                            }
                        }else {
                            this.loading=false
                        }

                    },
                    ' . "\n";
        } else {
            //no belongsTo Relation
            // $script.='
            // if(this.mode == \'update\') {
            //     if (val) {
            //         this.fetchObject()
            //     }
            // }else {
            //     this.loading=false
            // }
            // ';
        }
        $script .= '

            },

            data(){
                return {
                    //debug:true,
                    activityList:[],
                    sending:false,
                    loading:false,



                    object:{},
                    ';
        $components = [];
        $toLoad = [];
        foreach ($this->table->relationship() as $relation) {
            if (in_array($relation['laravel_name'], ['belongsTo']) && !in_array($relation['to_model_id'], $components)) {
                $script .= '';
                $related_model = \App\Table::find($relation['to_model_id']);
                $components[] = $relation['to_model_id'];
                $functionLoadName = $related_model->model . 'Loaded';
                $toLoad[] = $functionLoadName;
                $script .= '
                    showForm_' . $related_model->variable . ' : false,' . "\n";
                $script .= '
                    created' . $related_model->model . ' : {},' . "\n";
                $script .= '
                    ' . $related_model->model . 'List:[],' . "\n";
                $script .= '
                    ' . $related_model->model . 'Loaded:[],' . "\n";
            }
        }
        // if ($this->table->hasBelongsToRelation()){
        //     $toLoad = [];
        //     foreach ( $this->table->belongsToRelationList() as $relation) {
        //         $related_model = \App\Table::find($relation['to_model_id']);
        //         $functionLoadName = 'fetch'.$related_model->model.'Loaded';
        //         $toLoad[]=$functionLoadName;
        //         $script.='
        // '.$functionLoadName.':false,'."\n";
        //         // $script.=$functionLoadName.','."\n" ;
        //
        //     // '.$functionLoadName.' : function(){
        //     //     return this.'.$related_model->model.'List[0]? true : false
        //     // },
        //     //     '."\n";
        //
        //     }
        // }
        $script .= '



                };
            },

            filters:{


            },
            computed : {

                mode : function (){
                    if(this.forceMode){
                        return this.forceMode
                    }
                    return this.$route.params.' . strtolower(snake_case($this->table->model)) . '_id' . ' ? \'update\' : \'create\'

                },

                ';
        if ($this->table->hasBelongsToRelation()) {
            // $toLoad = [];
            // foreach ( $this->table->belongsToRelationList() as $relation) {
            //     $related_model = \App\Table::find($relation['to_model_id']);
            //     $functionLoadName = 'fetch'.$related_model->model.'Loaded';
            //     $toLoad[]=$functionLoadName;
            //     $script.='
            // '.$functionLoadName.' : function(){
            //     return this.'.$related_model->model.'List[0]? true : false
            // },
            //     '."\n";
            // }
            $script .= '
                    EverythingLoaded : function() {
                        return ';
            foreach ($toLoad as $function) {
                $script .= 'this.' . $function . ' && ';
                //this.fetchUserLoaded && this.fetchVehicleLoaded
            }
            $script = rtrim($script, '&& ');
            $script .= '
                    }
                    ' . "\n";
        }
        $script .= '
            },

            methods: {
                    fetchObject () {
                        this.$http.get(\'/api/' . $this->devis->app_name . '/' . $this->table->name . '/\'+this.$route.params.' . strtolower(snake_case($this->table->model)) . '_id' . ').then(function (response) {
                                  this.object = response.data.data
                                  this.loading=false

                              }, function (response) {
                                  // error callback
                              });
                    },

                 ' . "\n";
        $components = [];
        foreach ($this->table->relationship() as $relation) {
            if (in_array($relation['laravel_name'], ['belongsTo'])) {
                $script .= '';
                $related_model = \App\Table::find($relation['to_model_id']);
                $components[] = $relation['to_model_id'];
                $script .= '

                        //retrouver les données du belong to pour afficher la liste déroulante
                        fetch' . $related_model->model . '(){
                                this.$http.get(\'/api/' . $this->devis->app_name . '/' . $related_model->name . '\').then(function (response) {
                                          this.' . $related_model->model . 'List = response.data.data
                                          this.' . $related_model->model . 'Loaded = true
                                      }, function (response) {
                                          // error callback
                                      });
                        },';
            } elseif (in_array($relation['laravel_name'], ['hasMany'])) {
            }
        }
        $script .= '
                submit(object) {
                    this.sending=true

                    if(this.mode == \'create\'){
                        this.$http.post(\'/api/' . $this->devis->app_name . '/' . $this->table->name . '\', object).then(function (response) {
                            this.sending=false
                            this.object = response.data.data' . "\n";
        if ($this->table->hasPrimaries()) {
            $script .= '
                                this.createdId = response.data.data.' . $this->table->primary();
            $script .= '
                                this.createdObject = response.data.data
                                this.object={}';
            $script .= "\n";
        }
        $components = [];
        $script .= '
                            if (!this.forceMode) {
                                    ';
        if ($this->table->hasHasManyRelation() && $this->table->hasPrimaries()) {
            $script .= '
                                            this.$route.router.go(\'/' . $this->table->name . '/\'+object.' . $this->table->primary() . ')';
        } else {
            $script .= '
                                            this.$route.router.go(window.history.back())';
        }
        $script .= '
                            }

                            ';
        $script .= '
                        }, function (response) {
                            alert(\'erreur\')
                            setTimeout(function() { debugger; }, 10000)
                            throw new Error("Something went badly wrong!");
                        });

                    }// endif mode create
                    else if (this.mode == \'update\'){
                        ';
        if ($this->table->hasPrimaries()) {
            $script .= '
                        this.$http.put(\'/api/' . $this->devis->app_name . '/' . $this->table->name . '/\'+object.' . $this->table->primary() . ', object).then(function (response) {
                        this.sending=false
                        this.object = response.data.data' . "\n";
            $script .= '
                        this.createdObject = response.data.data' . "\n";
            //     $script.='
            // this.$route.router.go(\'/'.$this->table->name.'/\'+object.'.$this->table->primary().')';
            $script .= ' this.$route.router.go(\'/' . $this->table->name . '\')';
            // if ($this->table->hasHasManyRelation()) {
            // }else {
            //     $script.='this.$route.router.go(window.history.back())';
            // }
            $script .= '
                    }, function (response) {
                        alert(\'erreur\')
                        setTimeout(function() { debugger; }, 10000)
                        throw new Error("Something went badly wrong!");
                    });
                    ';
        }
        //end if ($this->table->hasPrimaries())
        $script .= '

                }//endif mode update


                },
                cancel() {
                    this.$route.router.go(window.history.back())
                },

                deleteObject(object) {
                    ';
        if ($this->table->hasPrimaries()) {
            $script .= '
                    this.$http.delete(\'/api/' . $this->devis->app_name . '/' . $this->table->name . '/\'+object.' . $this->table->primary() . ', object).then(function (response) {
                    this.sending=false

                    this.$route.router.go(\'/' . $this->table->name . '\')';
            $script .= '
                }, function (response) {
                    alert(\'erreur\')
                    setTimeout(function() { debugger; }, 10000)
                    throw new Error("Something went badly wrong!");
                });
                ';
        }
        //end if ($this->table->hasPrimaries()) {
        $script .= '

                },



                },




        }



        </script>

        ';
        // File::put('uploads/bootstrapping/'.$this->devis->app_name.'/vue_components/'.$this->table->model.'/form.vue',$script);
        $this->createFile($this->path(), $this->devis->app_name, $script);
    }
Beispiel #19
0
 public function handle()
 {
     // dd('<-----FORM------->',$this->devis, $this->table ,$this->view);
     var_dump('***********************************************************************************************************');
     var_dump($this->table->name);
     $viewScript = "@extends('layouts." . $this->table->the_namespace->theme->name . "')" . "\n\n";
     $viewScript .= "@section('menu')" . "\n";
     $viewScript .= $this->tab1 . "@include('" . $this->devis->app_name . "." . $this->space->name . "/" . $this->menuFileNameUsed() . "')" . "\n";
     $viewScript .= "@endsection" . "\n";
     $viewScript .= "\n\n";
     $viewScript .= "@section('content')" . "\n";
     $viewScript .= '<h1>' . $this->title . '</h1>';
     $viewScript .= "\n";
     $viewScript .= "\n";
     $hasHasManyRelation = false;
     $relatedHasManyModel = [];
     foreach ($this->table->fields as $field) {
         foreach ($field->relations as $relation) {
             var_dump($relation->pivot->laravel_name);
             if (in_array($relation->pivot->laravel_name, ['hasMany', 'belongsToMany', 'morphToMany'])) {
                 $hasHasManyRelation = true;
                 var_dump('HM');
                 $related_table = Field::find($relation->pivot->to_field_id)->table;
                 $relatedHasManyModel[] = $relation;
                 echo "related";
                 var_dump($related_table->name);
             }
         }
     }
     $viewScript .= "\n";
     if (!empty($relatedHasManyModel)) {
         // if ($hasHasManyRelation) {
         $viewScript .= "\n    <div>\n\n  <!-- Nav tabs -->\n  <ul class='nav nav-tabs' role='tablist'>\n    <li role='presentation' class='active'><a href='#general' aria-controls='general' role='tab' data-toggle='tab'>General</a></li>" . "\n";
         foreach ($relatedHasManyModel as $key => $relatedModel) {
             $viewScript .= "<li role='presentation'><a href='#" . $relatedModel->name . "' aria-controls='" . $relatedModel->name . "' role='tab' data-toggle='tab'>" . $relatedModel->name . "</a></li>" . "\n";
         }
         $viewScript .= "\n  </ul>\n\n  <!-- Tab panes -->\n  <div class='tab-content'>\n    <div role='tabpanel' class='tab-pane fade in active' id='general'>@include('" . $this->table->viewPathInController() . ".form')</div>" . "\n";
         //foreach ($relatedHasManyModel as $key => $relatedModel) {
         foreach ($this->table->fields as $field) {
             foreach ($field->relations as $relation) {
                 if (in_array($relation->pivot->laravel_name, ['belongsToMany', 'morphedByMany', 'morphToMany'])) {
                     $related_table = \App\Table::find($relation->pivot->to_model);
                 }
                 if (in_array($relation->pivot->laravel_name, ['hasMany', 'belongsTo'])) {
                     $related_table = Field::find($relation->pivot->to_field_id)->table;
                 }
                 $fromField = Field::find($relation->pivot->from_field_id);
                 $toField = Field::find($relation->pivot->to_field_id);
                 $toModel = $toField->table;
                 if ($field->relations()->where('from_field_id', $fromField->id)->wherePivot('laravel_name', 'hasMany')->count() > 1) {
                     $functionNamne = $related_table->variablePlural . '_' . $toField->name;
                     $functionNamne = ends_with($functionNamne, '_id') ? substr($functionNamne, 0, -3) : $functionNamne;
                     $functionNamne = camel_case($functionNamne);
                 } else {
                     $functionNamne = $related_table->variablePlural;
                 }
                 if (in_array($relation->pivot->laravel_name, ['hasMany', 'belongsToMany', 'morphToMany'])) {
                     $viewScript .= "<div role='tabpanel' class='tab-pane fade' id='" . $functionNamne . "'>\n                                    @forelse(\$" . $this->table->variable . "->" . $functionNamne . " as \$" . $relatedModel->variable . ")\n                                    {{ \$" . $relatedModel->variable . " }}\n                                    @empty\n                                    No " . $relatedModel->name . " Yet\n                                    @endforelse\n                                </div>" . "\n\n";
                 }
             }
         }
         //}
         $viewScript .= "\n\n  </div>\n\n</div>\n    ";
     } else {
         $viewScript .= $this->tab1 . "@include('" . $this->table->viewPathInController() . ".form')";
     }
     //$viewScript.= $this->tab1.'<h1>'.$this->view.'</h1>';
     $viewScript .= "\n";
     $viewScript .= "\n";
     $viewScript .= "@endsection";
     // $viewScript.="\n\n";
     $this->createFile('../resources/views/' . $this->devis->app_name . '/' . $this->table->the_namespace->name . '/' . $this->table->model . '/' . $this->view . '.blade.php', $this->devis->app_name, $viewScript);
 }
Beispiel #20
0
 public static function constructRouterVue____________________old(Table $table, $chaine_cumul = '', $chaine_list = '', $chaine_edit = '', $loop = 0)
 {
     var_dump($table->RouterVue);
     var_dump($loop);
     $chaine_cumul .= $table->name . '/';
     $chaine_list = str_replace('/', '/id/', $chaine_cumul);
     $chaine_edit = rtrim($chaine_list, '/id/');
     //put thre keys
     // $chaine_list.=$table->primary().'/';
     // $chaine_cumul.=$table->name.'/';
     foreach ($table->hasHasManyRelationList() as $relation) {
         // var_dump($relation);
         $toTable = Table::find($relation['to_model_id']);
         //var_dump(rtrim($chaine_list, '/'));
         //var_dump(rtrim($chaine_edit, '/'));
         Table::constructRouterVue($toTable, $chaine_cumul, $chaine_list, $chaine_edit, $loop++);
     }
     var_dump(rtrim($chaine_list, '/'));
     $table->RouterVue->push(['type' => 'list', 'route' => rtrim($chaine_list, '/')]);
     var_dump(rtrim($chaine_edit, '/'));
     $table->RouterVue[] = ['type' => 'list', 'route' => rtrim($chaine_list, '/')];
     // var_dump(rtrim($chaine_cumul, '/'));
     // if (isset($toTable)) {
     //Table::constructRouterVue($table, $chaine_cumul,  $chaine_list, $chaine_edit, $loop++);
     # code...
     // }
 }
    public function handle()
    {
        $script = '
        <style>
        .spacer{
            height: 50px;
            display: block;
        }
        </style>


        <template >
<pre>
    {{object | json}}
</pre>

<div v-for="data in dataList">
    <pre>{{data | json}}</pre>
</div>



            <div class="row" v-show="showForm">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">

                        <h5>General Information</h5>
                        <div class="row" v-if="mode==\'update\'">
                            <div class="col-md-12">
                                <div class="pull-right"><a @click="deleteObject(object)"> Detete this object</a></div>
                            </div>
                        </div>
                    </div>
                    <div class="ibox-content">

          <validator name="validation1">
            <form novalidate class="form-horizontal form-label-left">';
        foreach ($this->table->fields()->where('$field->is_on_mini_form', 1)->orderBy('order', 'asc')->get() as $field) {
            if ($field->is_incrementable || in_array($field->name, ['created_at', 'updated_at', 'updated_by'])) {
                continue;
            }
            $script .= $this->VueformType($field);
        }
        $script .= '

                <div class="col-sm-12">
                    <button @click="cancel"  class="btn btn-default pull-right">Cancel</button>
                    <button @click.prevent="submit(object)" class="btn btn-primary pull-right" :disabled="$validation1.invalid">
                        <span>Create</span>
                         contact <i class="fa fa-spin fa-spinner" v-show="sending"></i>
                     </button>

                </div>

            </form>
          </validator>


                    </div>
                </div>
            </div>
        </div>


        </template>





        <script>

        // import modal from \'../../snippets/modal.vue\'; ';
        $components = [];
        foreach ($this->table->relationship() as $relation) {
            if (in_array($relation['laravel_name'], ['belongsTo']) && !in_array($relation['to_model_id'], $components)) {
                $script .= '';
                $related_model = \App\Table::find($relation['to_model_id']);
                $components[] = $relation['to_model_id'];
                $script .= 'import ' . $related_model->vueComponentName('form') . ' from \'' . $this->table->vueComponentRelativePathTo($related_model, 'form') . '\'' . "\n";
            }
        }
        $script .= '




        export default {
            components: {
                // modal,
            },

            props :{



            },


            ready () {
                this.fetchActivities();
                //console.log(this.$parent.$parent.debug)
                //console.log(this.$parent.focus)


            },
            watch: {
                // \'object.crm_app.activity_id\': function (val, oldVal) {
                //     console.log(`value changed from ${oldVal} to ${val}`)
                // },
                \'$parent.focus\': function (val, oldVal) {
                    if (this.object) {
                        if (this.$parent.focus == this.object.id) {
                            this.focus=this.$parent.focus
                        }
                    }else {//create


                    }
                }

            },

            data(){
                return {
                    //debug:true,
                    activityList:[],
                    sending:false,
                    showForm:true,

                    focus:\'\',
                    object:{},


                    ';
        foreach ($this->table->relationship() as $relation) {
            if (in_array($relation['laravel_name'], ['belongsTo'])) {
                $script .= 'showForm_' . $related_model->variable . ' : false,' . "\n";
            }
        }
        $script .= '



                };
            },

            filters:{


            },
            computed : {
                keyList : function (){
                    var keys = [];
                    for(var k in this.dataList[0]) keys.push(k);
                    return keys;
                }
            },

            methods: { ';
        // foreach ($this->table->relationship() as $relation) {
        //     if (in_array(,['belongsTo'])$relation['laravel_name'] == 'belongsTo') {
        //         $script.='function showForm_'.$related_model->variable.'" {
        //             this.
        //         }';
        //     }
        // }
        $script .= '
                //retrouver les données du belong to pour afficher la liste déroulante
                fetchActivities(){
                        this.$http.get(\'\').then(function (response) {
                                  this.activityList = response.data.data

                              }, function (response) {
                                  // error callback
                              });
                },

                submit(object) {
                    this.sending=true

                        this.$http.post(\'/api/object\', object).then(function (response) {
                            this.sending=false
                            this.object = response.data.data



                        }, function (response) {
                            alert(\'erreur\')
                            setTimeout(function() { debugger; }, 10000)
                            throw new Error("Something went badly wrong!");
                        });
                    }

                },





            cancel() {
                this.$route.router.go(window.history.back())
            },



        }



        </script>

        ';
        // File::put('uploads/bootstrapping/'.$this->devis->app_name.'/vue_components/'.$this->table->model.'/form.vue',$script);
        $this->createFile($this->path(), $this->devis->app_name, $script);
    }
 public function delete_relation(Devis $devis, $from_field_id, $to_field_id)
 {
     $fromField = Field::find($from_field_id);
     $toField = Field::find($to_field_id);
     //dd($fromField->relations()->where('to_field_id', $to_field_id)->get());
     $laravel_name = $fromField->relations()->where('to_field_id', $to_field_id)->first()->pivot->laravel_name;
     if (in_array($laravel_name, ['belongsToMany'])) {
         $pivot_table_id = $fromField->relations()->where('to_field_id', $to_field_id)->first()->pivot->pivot_table_id;
     }
     $message = '';
     if ($fromField->relations()->detach($toField)) {
         if (in_array($laravel_name, ['belongsToMany'])) {
             //$pivot_table_id = $fromField->relations()->where('to_field_id', $to_field_id)->first()->pivot->pivot_table_id;
             DB::table('relationships')->where('on_field_id', $from_field_id)->where('pivot_table_id', $pivot_table_id)->delete();
             //suppression de la pivot_table
             Table::find($pivot_table_id)->remove();
         }
         if (in_array($laravel_name, ['hasMany', 'belongsTo'])) {
             $pivot_table_id = $toField->relations()->detach($fromField);
         }
         $message .= 'relationhip has been removed';
         if (!$fromField->is_primary) {
             // $fromField->delete();
             // $message.= 'the field <b>'.$fromField.'</b> has been removed. <br>';
         }
         if (!$toField->is_primary) {
             // $toField->delete();
             // $message.= 'the field <b>'.$toField.'</b> has been removed. <br>';
         }
     }
     if ($message) {
         Flash::success($message);
     } else {
         Flash::error('relation not found. Probably already deleted.');
     }
     return redirect()->back();
 }
    public function handle()
    {
        //
        $script = '

                <style>

                </style>



                <template>

                <h1>' . $this->table->model . '  Index</h1>

                    Mettre ici : <br>
                    - menu des relations à plusieurs<br>
                    - menu des specialcompo
                    - acces a list
                    - acces a create
                    <br>
                    <br>
                    et le router-view


                    ';
        $hasHasManyRelation = false;
        $ManyRelationQuantity_sup_4 = false;
        /*
                                    if ($table->hasHasManyRelation()) {
                                        $hasHasManyRelation = true;
                                        hasHasManyRelationList()->count();
                                    }
                                    $hasSpecialVueComponent = false;
                                    if ($this->getSpecialVueComponentList($table)) {
                                        $hasSpecialVueComponent = true;
                                    }
                                    ////
                                    if (!$hasHasManyRelation && !$hasSpecialVueComponent) { //C
                                        # code...
                                    }
        */
        $script = '








                            <template>


                            <div class=row>
                            <h1>Index <b>{{object.name}}</b></h1>
                            <!--<ui-icon-button icon="navigate_before" @click.prevent="goBack" tooltip="Go back" type="primary" color="default" class="pull-left" ></ui-icon-button>-->
                            </div>
                            ' . "\n";
        if ($this->table->hasHasManyRelation()) {
            $script .= '
                                <div class="tabbable">
                                    <ul class="nav nav-pills nav-stacked col-md-3">
                                        <li class="active"><a href="#general" data-toggle="tab">General</a></li>
                                        ';
            if ($this->getSpecialVueComponentList($this->table)) {
                foreach ($this->getSpecialVueComponentList($this->table) as $specialView) {
                    $script .= '<li><a href="#' . $specialView . '" data-toggle="tab">' . $specialView . '</a></li>';
                }
            } else {
                foreach ($this->table->hasHasManyRelationList() as $relation) {
                    $script .= '<li class=""><a href="#' . $relation['methodName'] . '" data-toggle="tab">' . $relation['methodName'] . '</a></li>';
                }
            }
            $script .= '
                                    </ul>
                                    <div class="tab-content col-md-8">
                                        <div class="tab-pane fade in active" id="general">
                                        ';
            if ($this->table->name == 'vehicles') {
                $script .= '
                                            <div>
                                                    <!-- Nav tabs -->
                                                    <ul class="nav nav-tabs" role="tablist">
                                                    <li role="presentation" class="active"><a href="#form" aria-controls="home" role="tab" data-toggle="tab">' . $this->table->model . ' form</a></li>
                                                    ';
                foreach ($this->table->hasHasManyRelationList() as $relation) {
                    $script .= '<li><a href="#' . $relation['methodName'] . '" role="tab" data-toggle="tab">' . $relation['methodName'] . '</a></li>';
                }
                $script .= '
                                                    </ul>

                                                    <!-- Tab panes -->
                                                    <div class="tab-content">
                                                    <div role="tabpanel" class="tab-pane active" id="form">
                                                         <' . $this->table->VueTag('form') . ' :created-object.sync="created' . $this->table->model . '" ></' . $this->table->VueTag('form') . '>
                                                    </div>
                                                    ';
                foreach ($this->table->hasHasManyRelationList() as $relation) {
                    $related_model = \App\Table::find($relation['to_model_id']);
                    $fromField = \App\Field::find($relation['from_field_id']);
                    $script .= '
                                                               <div class="tab-pane fade in" id="' . $relation['methodName'] . '">
                                                                  <' . $related_model->VueTag('list', $relation['methodName']) . ' :from-id="getId" :url="getUrl(\'' . $relation['methodName'] . '\')"></' . $related_model->VueTag('list', $relation['methodName']) . '>
                                                               </div>';
                    $script .= '' . "\n";
                }
                $script .= '
                                                    </div>

                                                    </div>
                                            ';
            } else {
                $script .= ' <' . $this->table->VueTag('form') . ' :created-object.sync="created' . $this->table->model . '" ></' . $this->table->VueTag('form') . '> ';
            }
            $script .= '
                                        </div>
                                        ';
            if ($this->getSpecialVueComponentList($this->table)) {
                foreach ($this->getSpecialVueComponentList($this->table) as $specialView) {
                    $script .= '
                                            <div class="tab-pane fade in" id="' . $specialView . '">
                                                <' . $this->table->VueTag('', $specialView) . ' :' . $this->table->variable . '="object"></' . $this->table->VueTag('', $specialView) . '>

                                             </div>
                                            ';
                }
            } else {
                foreach ($this->table->hasHasManyRelationList() as $relation) {
                    $related_model = \App\Table::find($relation['to_model_id']);
                    $fromField = \App\Field::find($relation['from_field_id']);
                    $script .= '
                                                       <div class="tab-pane fade in" id="' . $relation['methodName'] . '">
                                                          <' . $related_model->VueTag('list', $relation['methodName']) . ' :from-id="getId()" :url="getUrl(\'' . $relation['methodName'] . '\')"></' . $related_model->VueTag('list', $relation['methodName']) . '>
                                                       </div>';
                    ///api/'.$this->devis->app_name.'/'.$this->table->name.'//'.strtolower($relation['methodName']).'
                    $script .= '' . "\n";
                    // $script.=$this->tab1.'import '.$related_model->vueComponentName('list') . ' from \'' . $this->table->vueComponentRelativePathTo($related_model, 'list').'\''."\n";
                }
            }
            $script .= '
                                    </div><!--tab content-->
                                </div>
                                ';
        } else {
            //doesn't have has many relation
            //-->load the form
            $script .= '<router-view></router-view>
                                #98789444da9 --> router-view -> Afficher le formulaire #98789444da9
                                ';
        }
        if ($this->table->name == 'vehicles') {
            $script .= '
                                        <h3>Financials</h3>

                                        <graph-line2></graph-line2>
                                        <h4>Actual</h4>

                                        <h4>Budget</h4>


                                        <h3>Cash fLOW FORECAST</h3>
                                        <graph-line1></graph-line1>


                                        ' . "\n\n";
        }
        $script .= '</template>' . "\n\n";
        $script .= "\n\n";
        $script .= '<script>' . "\n\n";
        $components = [];
        $script .= $this->tab1 . 'import ' . $this->table->vueComponentName('form') . ' from \'' . $this->table->vueComponentRelativePathTo($this->table, 'form') . '\'' . "\n";
        $components[] = $this->table->vueComponentName('form');
        $relationToModel = [];
        /*
         **  ajout des composant des relations
         */
        foreach ($this->table->hasHasManyRelationList() as $relation) {
            $related_model = \App\Table::find($relation['to_model_id']);
            $fromField = \App\Field::find($relation['from_field_id']);
            $componentName = $related_model->vueComponentName('list', $relation['methodName']);
            $path = $this->table->vueComponentRelativePathTo($related_model, 'list');
            // $relationToModel[]=$related_model->name;
            $components[] = $componentName;
            $script .= 'import ' . $componentName . ' from \'' . $path . '\'' . "\n";
            //$script.=$this->tab1.'import '.$related_model->vueComponentName('list') . ' from \'' . $this->table->vueComponentRelativePathTo($related_model, 'list').'\''."\n";
        }
        /*
         ** Ajout des special components
         */
        if ($this->getSpecialVueComponentList($this->table)) {
            foreach ($this->getSpecialVueComponentList($this->table) as $specialView) {
                $componentName = $this->table->vueComponentName('', $specialView);
                $path = $this->table->vueComponentRelativePathTo($this->table, $specialView);
                $components[] = $componentName;
                $script .= 'import ' . $componentName . ' from \'' . $path . '\'' . "\n";
            }
        }
        $script .= '


                            export default {
                                components: {' . "\n";
        foreach ($components as $component) {
            $script .= $this->tab4 . $component . ', ' . "\n";
        }
        $script .= '
                                },

                                props :{

                                },

                                ready () {
                                    this.fetchObject()
                                },
                                watch: {
                                    // \'object.crm_app.activity_id\': function (val, oldVal) {
                                    //     console.log(`value changed from ${oldVal} to ${val}`)
                                    // },


                                },

                                data(){
                                    return {

                                        object:{},
                                        ';
        $components = [];
        foreach ($this->table->relationship() as $relation) {
            if (in_array($relation['laravel_name'], ['belongsTo']) && !in_array($relation['to_model_id'], $components)) {
                $script .= '';
                $related_model = \App\Table::find($relation['to_model_id']);
                $components[] = $relation['to_model_id'];
                $script .= '
                                        showForm_' . $related_model->variable . ' : false,' . "\n";
                $script .= '
                                        created' . $related_model->model . ' : {},' . "\n";
                $script .= '
                                        ' . $related_model->model . 'List:[],' . "\n";
            }
        }
        $script .= '

                                    };
                                },

                                filters:{

                                },
                                computed : {
                                    getId(){
                                        return this.$route.params.' . strtolower(snake_case($this->table->model)) . '_id' . '
                                    }

                                },

                                methods: {
                                    fetchObject () {
                                        this.$http.get(\'/api/' . $this->devis->app_name . '/' . $this->table->name . '/\'+this.$route.params.' . strtolower(snake_case($this->table->model)) . '_id' . ').then(function (response) {
                                                  this.object = response.data.data
                                                  this.loading=false

                                              }, function (response) {
                                                  // error callback
                                              });
                                    },
                                    goBack(){
                                        this.$route.router.go(window.history.back())
                                    },
                                    getUrl(methodName){
                                        id = this.$route.params.' . strtolower(snake_case($this->table->model)) . '_id' . '
                                        return \'api/' . $this->devis->app_name . '/' . $this->table->name . '/\'+id+\'/\'+methodName
                                    },
                                    getId(){
                                        return this.$route.params.' . strtolower(snake_case($this->table->model)) . '_id' . '
                                    }
                                },
                            }

                            ';
        // dd($script);
        $script .= '</script>' . "\n\n";
        $script .= '<style>' . "\n\n";
        $script .= '</style>' . "\n\n";
        // File::put('uploads/bootstrapping/'.$this->devis->app_name.'/vue_components/'.$this->table->model.'/list.vue',$script);
        $this->createFile($this->path(), $this->devis->app_name, $script);
    }
Beispiel #24
0
 public function handle()
 {
     foreach ($this->devis->tables()->where('model', '<>', '')->get() as $a => $table) {
         // echo '<h5>&nbsp;&nbsp;&nbsp;&nbsp;<i style="color:green">></i> Preparing UnitTest for table <u style="color:#15c">';
         // echo $table->name;
         // echo '</u></h5>';
         $modelScript = '<?php' . "\n\n";
         //
         // $modelScript.='namespace '.$table->modelNamespace().';'."\n\n";
         //
         // $modelScript.='use Illuminate\Database\Eloquent\Model;'."\n\n";
         $useList = [];
         // if($table->name == 'users'){
         foreach ($table->fields as $field) {
             // echo $field->name.'<br>';
             foreach ($field->relations as $relation) {
                 if (in_array($relation->pivot->laravel_name, ['belongsToMany', 'morphedByMany', 'morphToMany'])) {
                     $related_table = \App\Table::find($relation->pivot->to_model);
                 }
                 if (in_array($relation->pivot->laravel_name, ['hasMany', 'belongsTo'])) {
                     $related_table = Field::find($relation->pivot->to_field_id)->table;
                 }
                 $useList[] = $related_table->modelNamespaceClass();
                 // echo $relation->table->modelNamespaceClass();
             }
         }
         // dd('class=>',$table->modelNamespaceClass(), 'uses=>', $useList);
         // }
         // var_dump($this->renderUsesStatements($useList));
         $modelScript .= $this->renderUsesStatements($useList);
         $modelScript .= 'class ' . $table->model . ' extends Model' . "\n";
         $modelScript .= '{' . "\n\n";
         $modelScript .= $this->tab1 . 'protected $guarded = [];' . "\n";
         $modelScript .= $this->tab1 . 'protected $table = "' . $table->tablename . '";' . "\n";
         $modelScript .= "\n";
         foreach ($table->relationship() as $relation) {
             if ($relation['laravel_name'] == 'belongsTo') {
                 $defaultFieldName = strtolower(snake_case($relation['to_model'])) . '_id';
                 $modelScript .= $this->tab1 . 'public function ' . $relation['methodName'] . '() {' . "\n";
                 $modelScript .= $this->tab2 . 'return $this->belongsTo(' . $relation['to_model'] . '::class';
                 $showfirstArg = false;
                 if ($relation['from_field'] != $defaultFieldName) {
                     $showfirstArg = true;
                     $modelScript .= ', "' . $relation['from_field'] . '"';
                 }
                 if ($relation['to_field'] != 'id') {
                     if (!$showfirstArg) {
                         $modelScript .= ', "' . $relation['from_field'] . '"';
                     }
                     $modelScript .= ', "' . $relation['to_field'] . '"';
                 }
                 $modelScript .= ');' . "\n";
                 $modelScript .= $this->tab1 . '}' . "\n";
             }
             if ($relation['laravel_name'] == 'hasMany') {
                 $defaultFieldName = strtolower(snake_case($relation['model'])) . '_id';
                 $modelScript .= $this->tab1 . 'public function ' . $relation['methodName'] . '() {' . "\n";
                 $modelScript .= $this->tab2 . 'return $this->hasMany(' . $relation['to_model'] . '::class';
                 if ($relation['to_field'] != $defaultFieldName) {
                     $modelScript .= ', "' . $relation['from_field'] . '"';
                 }
                 if ($relation['from_field'] != 'id') {
                     $modelScript .= ', "' . $relation['to_field'] . '"';
                 }
                 $modelScript .= ');' . "\n";
                 $modelScript .= $this->tab1 . '}' . "\n";
             }
             if ($relation['laravel_name'] == 'belongsToMany') {
                 # code...
             }
         }
         $modelScript .= "\n\n";
         $modelScript .= '}' . "\n\n";
         // $modelScript='';
         // echo "------>";
         // var_dump('../app/Models/'.$this->devis->app_name.'/'.$table->the_namespace->name.'/'.$table->model.'.php',$this->devis->app_name,$modelScript);
         $this->createFile('../app/Models/' . $this->devis->app_name . '/' . $table->the_namespace->name . '/' . $table->model . '.php', $this->devis->app_name, $modelScript, true);
         // die('++');
         //dd('123');
         // if ($table->name == 'users') {
         //     dd($modelScript);
         // }
     }
     //dd('stop script model');
 }
Beispiel #25
0
 public function formTtpe(Field $field)
 {
     $toReturn = "\n\n        <div class='form-group @if (\$errors->has('" . $field->name . "')) has-error  @endif'>\n        {!!Form::label('" . $field->name . "', '{$field->label}', array('class' => 'control-label '));!!}\n        <div class=''> " . "\n";
     $has_relation = false;
     foreach ($field->relations as $relation) {
         if (in_array($relation->pivot->laravel_name, ['belongsTo'])) {
             $has_relation = true;
             $related_model = \App\Field::find($relation->pivot->to_field_id)->table;
             $basePath = $related_model->devis->app_name . '.' . $related_model->the_namespace->name . "." . $related_model->variable;
             if ($this->table->the_namespace->name == 'Web') {
                 $basePath = $related_model->devis->app_name . "." . $related_model->variable;
             }
             $toReturn .= "{!! Form::select('" . $field->name . "', \$" . $related_model->variablePlural . ", null, ['class'=>'form-control " . $field->name . "']) !!}" . "\n";
             $toReturn .= "<a target='_blank' class='pull-right btn btn-sm btn-success' href='{{route('" . $basePath . ".create')}}'><i class='fa fa-plus'></i> Create a " . $related_model->variable . "</a>" . "\n";
             // $toReturn.="<script>
             //     $('select[name=".$field->name."]').select2({
             //         placeholder: '".$field->placeholder."',
             //         allowClear: true
             //     });
             // </script>"."\n";
         } elseif ($relation->pivot->laravel_name == 'belongsToMany') {
             $has_relation = true;
             $related_model = \App\Table::find($relation->pivot->to_model);
         }
     }
     if (!$has_relation) {
         $toReturn .= "\t\t";
         switch ($field->type->name) {
             case 'integer':
                 $toReturn .= "{!! Form::number('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control ', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'string':
                 $toReturn .= "{!! Form::text('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control ', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'password':
                 $toReturn .= "{!! Form::password('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control ', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'email':
                 $toReturn .= "{!! Form::email('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control ', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'dateTime':
                 $toReturn .= "{!! Form::date('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control datepicker', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'datetime':
                 $toReturn .= "{!! Form::date('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control datepicker', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'time':
                 $toReturn .= "{!! Form::date('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control datepicker', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'text':
                 $toReturn .= "{!! Form::textarea('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control ', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'mediumtext':
                 $toReturn .= "{!! Form::textarea('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control ', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'longtext':
                 $toReturn .= "{!! Form::textarea('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control ', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'binary':
                 $toReturn .= "{!! Form::textarea('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control ', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'decimal':
                 $toReturn .= "{!! Form::number('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control ', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'bigint':
                 $toReturn .= "{!! Form::number('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control ', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             case 'boolean':
                 $toReturn .= "<label class='radio-inline'>{!! Form::radio('" . $field->name . "', 1, ['class' => '']) !!} @lang('core.yes')</label>" . "\n";
                 $toReturn .= "<label class='radio-inline'>{!! Form::radio('" . $field->name . "', 0, ['class' => '']) !!} @lang('core.no')</label>" . "\n";
                 break;
             case 'date':
                 $toReturn .= "{!! Form::date('" . $field->name . "', Input::old('" . $field->name . "') ,  ['class' => 'form-control datepicker', 'placeholder'=>'" . $field->placeholder . "']) !!}" . "\n";
                 break;
             default:
                 # code...
                 break;
         }
     }
     $toReturn .= " </div><p class='text-danger'>@if (\$errors->has('" . $field->name . "')) <span class='error'>{{ \$errors->first('" . $field->name . "') }}</span> @endif</p></div> " . "\n\n";
     return $toReturn;
 }
Beispiel #26
0
 public function testRelations()
 {
     foreach ($this->tables()->where('model', '<>', '')->get() as $a => $table) {
         echo '<h5>&nbsp;&nbsp;&nbsp;&nbsp;<i style="color:green">></i> Preparing files for table <u style="color:#15c">';
         echo $table->name;
         echo '</u></h5>';
         $modelScript = '<?php' . "\n\n";
         $modelScript .= 'namespace ' . $table->modelNamespace() . ';' . "\n\n";
         $modelScript .= 'use Illuminate\\Database\\Eloquent\\Model;' . "\n\n";
         $useList = [];
         // if($table->name == 'users'){
         foreach ($table->fields as $field) {
             // echo $field->name.'<br>';
             foreach ($field->relations as $relation) {
                 // echo "<h1>".$relation->pivot->laravel_name."</h1>";
                 if ($relation->pivot->laravel_name == 'belongsToMany') {
                     $related_table = \App\Table::find($relation->pivot->to_model);
                     // $related_field = \App\Field::find($relation->pivot->on_field_id);
                     // $useList[]=$related_table->modelNamespaceClass();
                 } else {
                     $related_table = Field::find($relation->pivot->to_field_id)->table;
                 }
                 $useList[] = $related_table->modelNamespaceClass();
                 // echo $relation->table->modelNamespaceClass();
             }
         }
         // dd('class=>',$table->modelNamespaceClass(), 'uses=>', $useList);
         // }
         // var_dump($this->renderUsesStatements($useList));
         var_dump($useList);
         $modelScript .= 'class ' . $table->model . ' extends Model' . "\n";
         $modelScript .= '{' . "\n\n";
         // $modelScript.="\t TESTSTSTSTS";
         $modelScript .= $this->tab1 . 'protected $guarded = [];' . "\n";
         $modelScript .= $this->tab1 . 'protected $table = "' . $table->tablename . '";' . "\n";
         $modelScript .= "\n";
         foreach ($table->fields as $field) {
             foreach ($field->relations as $relation) {
                 if (isset($relation->name)) {
                     $related_table = Field::find($relation->pivot->to_field_id)->table()->first();
                     if ($relation->pivot->laravel_name == 'morphedByMany') {
                         $modelScript .= $this->tab1 . 'public function ' . $related_table->variablePlural . '() {' . "\n";
                         $relation->pivot->to_field_id = Field::find($relation->pivot->to_field_id)->name;
                         $modelScript .= $this->tab2 . 'return $this->morphedByMany(' . $related_table->modelNamespaceClass() . '::class);' . "\n";
                         $modelScript .= $this->tab1 . '}' . "\n";
                     }
                     if ($relation->pivot->laravel_name == 'belongsTo') {
                         $modelScript .= $this->tab1 . 'public function ' . $related_table->variable . '() {' . "\n";
                         $relation->pivot->to_field_id = Field::find($relation->pivot->to_field_id)->name;
                         $modelScript .= $this->tab2 . 'return $this->belongsTo(' . $related_table->modelNamespaceClass() . '::class);' . "\n";
                         $modelScript .= $this->tab1 . '}' . "\n";
                     }
                     if ($relation->pivot->laravel_name == 'hasMany') {
                         $modelScript .= $this->tab1 . 'public function ' . $related_table->variablePlural . '() {' . "\n";
                         $relation->pivot->to_field_id = Field::find($relation->pivot->to_field_id)->name;
                         $modelScript .= $this->tab2 . 'return $this->hasMany(' . $related_table->modelNamespaceClass() . '::class);' . "\n";
                         $modelScript .= $this->tab1 . '}' . "\n";
                     }
                     // var_dump($relation->name);
                 }
             }
         }
         $modelScript .= "\n\n";
         $modelScript .= '}' . "\n\n";
         // $modelScript='';
         // echo "------>";
         // if ($table->name == 'users') {
         //     dd($modelScript);
         // }
     }
     //dd('stop script model');
 }
Beispiel #27
0
    public function VueformType(Field $field)
    {
        $asterix = '';
        if ($field->isRequired()) {
            $asterix = '<span class="text-danger">*</span>';
        }
        $toReturn = '

            <div class="form-group ' . $field->name . '">
                <div class="col-md-12 col-sm-12 ">
                <label for="' . $field->name . '" class="col-sm-2 control-label">' . $field->label . ' ' . $asterix . '</label>
                <div class="col-sm-10 "> ' . "\n";
        $has_relation = false;
        foreach ($field->relations as $relation) {
            if (in_array($relation->pivot->laravel_name, ['belongsTo'])) {
                $has_relation = true;
                $related_model = \App\Field::find($relation->pivot->to_field_id)->table;
                $toReturn .= '

                    <div v-if="!showForm_' . $related_model->variable . '">
                        <select v-model="object.' . $field->name . '" class="form-control" ' . $field->vueValidateField() . '>
                            <option v-for="' . $related_model->model . ' in ' . $related_model->model . 'List" :value="' . $related_model->model . '.' . $related_model->primary() . '"> ';
                foreach ($related_model->fields()->where('is_on_foreign_label', 1)->orderBy('order', 'asc')->get() as $foreignLabel) {
                    $toReturn .= '
                                    {{ ' . $related_model->model . '.' . $foreignLabel->name . ' }} ';
                }
                $toReturn .= '
                            </option>
                        </select>
                        ';
                if ($field->hasValidation()) {
                    $toReturn .= '
                        <div class="errors">
                            ' . $field->vueValidationErrors() . '
                        </div>
                    </div>' . "\n";
                }
                $toReturn .= '
                        <div v-else>
                            <input type="text" v-model="created' . $related_model->model . '.' . $related_model->primary() . '"  v-validate:' . $field->vueValidationVariable() . '="{required:true}">
                        </div>';
                // $toReturn.="<a target='_blank' class='pull-right btn btn-sm btn-success' href='{{route('".$basePath.".create')}}'><i class='fa fa-plus'></i> Create a ".$related_model->variable."</a>"."\n";
                $toReturn .= '
                    <ui-icon-button v-if="!showForm_' . $related_model->variable . '" icon="add" @click.prevent="showForm_' . $related_model->variable . '= ! showForm_' . $related_model->variable . ', this.object.' . $related_model->variable . '_id=\'\'" tooltip="Add" type="normal" color="primary" class="pull-right" ></ui-icon-button>

                    <ui-icon-button v-if="showForm_' . $related_model->variable . '" icon="remove" @click.prevent="showForm_' . $related_model->variable . '= ! showForm_' . $related_model->variable . '" tooltip="cancel" type="normal" color="default" class="pull-right" ></ui-icon-button>

                    <div class="well" v-if="showForm_' . $related_model->variable . '">

                        <div v-if="created' . $related_model->model . '.' . $related_model->primary() . '">' . "\n";
                $toReturn .= $this->tab7 . '<b>';
                foreach ($related_model->fields()->where('is_on_foreign_label', 1)->orderBy('order', 'asc')->get() as $foreignLabel) {
                    $toReturn .= '
                                {{ created' . $related_model->model . '.' . $foreignLabel->name . ' }} ';
                }
                $toReturn .= '
                            </b>

                        </div>
                        <div v-else>
                            <' . $related_model->VueTag('form') . ' force-mode="create" :created-object.sync="created' . $related_model->model . '" ></' . $related_model->VueTag('form') . '>
                        </div>
                    </div>
                    ' . "\n";
                //:created-id.sync="object[\''.$field->name.'\']"
            } elseif ($relation->pivot->laravel_name == 'belongsToMany') {
                $has_relation = true;
                $related_model = \App\Table::find($relation->pivot->to_model);
            }
        }
        if (!$has_relation) {
            $toReturn .= "\t\t";
            switch ($field->type->name) {
                case 'integer':
                case 'decimal':
                case 'bigint':
                    $toReturn .= '
                    <input type="number" class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'string':
                    $toReturn .= '
                    <input type="text" class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'password':
                    $toReturn .= '
                    <input type="password" class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'email':
                    $toReturn .= '
                    <input type="email" class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'currency':
                    $toReturn .= '<input type="date" class="form-control datepicker" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                <div class="errors">
                    ' . $field->vueValidationErrors() . '
                </div>' . "\n";
                    }
                    break;
                case 'dateTime':
                case 'datetime':
                case 'time':
                case 'date':
                    $toReturn .= '<input type="date" class="form-control datepicker" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'text':
                case 'mediumtext':
                case 'longtext':
                    $toReturn .= '
                    <textarea class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '></textarea>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'binary':
                    $toReturn .= '
                    <textarea class="form-control" v-model="object.' . $field->name . '" placeholder="' . $field->placeholder . '" ' . $field->vueValidateField() . '></textarea>' . "\n";
                    if ($field->hasValidation()) {
                        $toReturn .= '
                    <div class="errors">
                        ' . $field->vueValidationErrors() . '
                    </div>' . "\n";
                    }
                    break;
                case 'boolean':
                    $toReturn .= '
                    <!--
                    <label class="radio-inline">
                        <input v-model="object.' . $field->name . '" type="radio" value="1"> Yes
                    </label>
                    <label class="radio-inline">
                        <input v-model="object.' . $field->name . '" type="radio" value="0"> No
                    </label>-->

                    <ui-switch :value.sync="object.' . $field->name . '" label="" ></ui-switch>
                        ';
                    break;
            }
        }
        // $toReturn.=" </div><p class='text-danger'>@if (\$errors->has('".$field->name."')) <span class='error'>{{ \$errors->first('".$field->name."') }}</span> @endif</p></div> "."\n\n";
        $toReturn .= '
                </div>
            </div>
        </div>
    ' . "\n\n";
        return $toReturn;
    }