Database log in Laravel 5.4?

Asked

Viewed 97 times

0

I caught a project in progress but still do not know very well the Laravel, 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 log the data by 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 seems silly thing but I’m not getting past it, the database is already working, including entering a project manually by phpMyAdmin and do the view from that project to the user.

What can I do to fix this?

Below follows the view as requested. It’s a bit large, note that the component should be picked up by the "side-bar":

Project name Description Probability of Comprehensiveness %

Model

Approach Liquid - Vapour Liquid - Liquid Liquid phase model Wilson UNIQUAQ NRTL VAN Steam phase model Peng-Robinson SRK Manly 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')

Concoction

<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

  • the error seems to be in your create.blade.php view

  • Undefined variable contained in its View? post your View

1 answer

0

Inside the create.Blade view it expects a variable called Components that you are not sending in Exception or Validator fail. And your Insert is wrong the right would be so:

 $project = Project::create($request->all());

Browser other questions tagged

You are not signed in. Login or sign up in order to post.