Laravel - Multiple page form; Best Practices

0

I'm developing a system in Laravel where there will be several research projects (the validation of each form is a bit complex).

Schema::create('projetos', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name'); // Nome do projeto
    $table->string('view_route'); //rota do projeto
    $table->string('model_name'); //model que irá usar
    $table->string('title')->unique();
    $table->string('description');
    $table->string('slug')->unique();
    $table->timestamps();
});


<form method="POST" action="{{ action('SurveyController@insert') }}" >
    <input type="hidden" name="id" value="1"/>  
    <div class="page-1">
        <!-- Diversos Inputs aqui -->
    </div>
    <div class="page-2">
        <!-- Diversos Inputs aqui -->
    </div>
    <div class="page-3">
        <!-- Diversos Inputs aqui -->
    </div>
    <div class="page-4">
        <!-- Diversos Inputs aqui -->
    </div>
</form>

You will only have Controller to delegate each search.

My idea is to make a single <form /> (with all inputs in) to send to the bank at once only (will be sent only on the last page, by clicking the finish button), validation would be done only on the front end and to page, I would use a plugin (like jquery-steps for example). Is it a good practice to put the Model name and the View path in the database? hence, I would not need to create multiple Controllers for each new search that will be developed, I would only need to create Model and View . for example:

SurveyController

//Irá ter apenas um ''Controller'' para delegar cada pesquisa.
public function index($id)
{
    //$id é o id do projeto
    $project = Projeto::findOrFail($id);
    return view($project->view_route)->with(compact(['project']));
}

public function insert(Request $request)
{
    //não sei se vai funcionar, mas a idéia é essa:
    $project = Projeto::findOrFail($request->input('id'));
    $model = $project->model_name;
    $newModel = new $model;
    $newModel->insert(
        $request->all() //os inputs terão o mesmo nome das colunas do banco
    );
}
    
asked by anonymous 03.05.2017 / 21:58

0 answers