Data record in the Database in Laravel 5.4?

0

I've got a project in progress but I still do not know Laravel very well, and I'm trying to save the data in the database using this code in controller :

public function store(Request $request)
{
    $validator = \Validator::make($request->all(), [
        'name' => 'required',
        'description' => 'required',
        'coverage' => 'required',

    ]);

    if($validator->fails()) {
        flash($validator->errors)->error();
        return view('projects.create');
    }

    try {
        $project = $this->repository->store($request->all());
        flash('O projeto '. $project->name .' foi criado com sucesso!')->success();
        return redirect()->route('projects.show', ['id'=> $project->id]);
    } catch (\Exception $e) {
        flash($e->getMessage())->error();
        return view('projects.create');
    }
    dd($request);
}

When trying to register the data through the site I get the following error:

  

(2/2) ErrorException   Undefined variable: components (View: C: \ xampp \ htdocs \ thermopeu \ resources \ views \ projects \ create.blade.php)

It looks like a beast but I can not seem to get past it, the database is already working, including inserting a project manually by phpMyAdmin and making this project to the user.

What can I do to resolve this?

Below is the view as requested. It's a bit big, note that the component should be taken by the "side-bar":

                                           Project name                                                            description                                                                                 Probability of Coverage                                                                       %                                                                      

Template

                                                                Approach                                              Liquid - Steam                         Liquid - Liquid                                                                                                      Liquid phase model                                              Wilson                         UNIQUAQ                         NRTL                         VAN                                                                                                      Steam phase model                                              Peng-Robinson                         SRK                         Virial                                                                                             advanced options              
<!-- Advanced Options -->
<div class="advancedOptions collapse" id="advancedOptions">
    <!-- Navigation Tabs -->
    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#optimization" aria-controls="optimization" role="tab" data-toggle="tab">Otimização</a></li>
        <li role="presentation"><a href="#graphics" aria-controls="graphics" role="tab" data-toggle="tab">Gráficos</a></li>
        <li role="presentation"><a href="#reports" aria-controls="reports" role="tab" data-toggle="tab">Relatórios</a></li>
    </ul>

    <div class="panel panel-default">
        <div class="panel-body">
            <!-- Navigation Panes -->
            <div class="tab-content">
                <!-- Optimization Options -->
                <div role="tabpanel" class="tab-pane active" id="optimization">
                    <div class="form-group">
                        <label class="control-label" for="optimization_method">Método</label>
                        <select class="form-control" name="method">
                            <option value="PSO">PSO-Padrão</option>
                            <option value="HPSO">HPSO</option>
                        </select>
                    </div>
                </div>

                <!-- Graphics Options -->
                <div role="tabpanel" class="tab-pane" id="graphics">
                    <div class="form-group">
                        <input type="checkbox" id="grandezas-entrada" name="graphic_inputs" checked>
                        <label class="control-label" for="grandezas-entrada">Grandezas de Entrada</label>
                    </div>
                    <div class="form-group">
                        <input type="checkbox" id="otimizacao" name="graphic_optmization">
                        <label class="control-label" for="otimizacao">Otmização</label>
                    </div>
                    <div class="form-group">
                        <input type="checkbox" id="regiao-abrangencia" name="graphic_coverage_area" checked>
                        <label class="control-label" for="regiao-abrangencia">Região de Abrangência</label>
                    </div>
                    <div class="form-group">
                        <input type="checkbox" id="grandezas-saida" name="graphic_outputs" checked>
                        <label class="control-label" for="grandezas-saida">Grandezas de Saída</label>
                    </div>
                    <div class="form-group">
                        <input type="checkbox" id="predicao" name="graphic_prediction" checked>
                        <label class="control-label" for="predicao">Predição</label>
                    </div>
                    <div class="form-group">
                        <input type="checkbox" id="analise-residuo" name="graphic_waste_analysis">
                        <label class="control-label" for="analise-residuo">Análise de Resíduo</label>
                    </div>
                </div>

                <!-- Reports Options -->
                <div role="tabpanel" class="tab-pane" id="reports">
                    <div class="form-group">
                        <input type="checkbox" id="grandezas-entrada" name="report_parameters" checked>
                        <label class="control-label" for="grandezas-entrada">Parâmetros</label>
                    </div>
                    <div class="form-group">
                        <input type="checkbox" id="otimizacao" name="report_optmization" checked>
                        <label class="control-label" for="otimizacao">Otmização</label>
                    </div>
                    <div class="form-group">
                        <input type="checkbox" id="predicao" name="report_prediction" checked>
                        <label class="control-label" for="predicao">Predição</label>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@stop

@section ('sidebar')     

Mixture

<div class="component-list">

    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#components" aria-controls="components" role="tab" data-toggle="tab">Componentes</a></li>
        <li role="presentation"><a href="#parameters" aria-controls="parameters" role="tab" data-toggle="tab">Parâmetros</a></li>
    </ul>

    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="components">
            <div class="panel panel-defalt">
                <ul class="list-group">
                    <div class="empty-list">
                        Nenhum componente selecionado
                    </div>
                </ul>
                <div class="panel-footer text-right">
                    <button type="button" id="btnManageComponents" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#modalComponentModal">Incluir componentes</button>
                </div>
            </div>
        </div>
        <div role="tabpanel" class="tab-pane" id="parameters">
            <div class="panel panel-defalt">
                <div class="panel-body">
                    hello
                </div>
                <div class="panel-footer text-right">
                    <button type="button" id="btnViewModel" class="btn btn-sm btn-primary">Ver modelo</button>
                </div>
            </div>
        </div>
    </div>

</div>
<h2>Dados Experimentais</h2>
<div class="panel panel-default">
    <div class="panel-body text-center">
        Nenhum dado experimental selecionado
        {{--
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td class="text-left">Conjunto de dados #2</td>
                    <td class="text-right" width="20%"><span class="label label-primary">Otimização</span></td>
                    </tr>
                <tr>
                    <td class="text-left">Conjunto de dados #3</td>
                    <td class="text-right" width="20%"><span class="label label-success">Validação</span></td>
                </tr>
            </tbody>
        </table>
        <small>Você possui <b>3</b> conjuntos de dados cadastrados para este projeto</small> --}}
    </div>
    <div class="panel-footer text-right">
        <button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#modalDataModal">Incluir dados experimentais</button>
    </div>
</div>

@include ('projects.modals.components', ['components' = > $ components]) @include ('projects.modals.data') @include ('projects.modals.optimization')

@stop

@section ('styles')      @stop

@section ('scripts')               

</script>

@stop

    
asked by anonymous 23.11.2017 / 19:04

1 answer

0

Inside the create.blade view it expects a variable called components that you are not sending in the exception or validator fail. And your insert is wrong the right would be like this:

 $project = Project::create($request->all());
    
23.11.2017 / 21:17