I'm developing a project control application. Each project has its tasks, that is, when I create a task, it needs to be linked to the project. I'm using the Laravel feature of Route resource. When I pass the project id to the route, it does not identify when it enters the store method.
task creation form:
<div class="modal fade" id="tarefa" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="exampleModalLabel"><i class="fa fa-edit"></i> Nova tarefa</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{{ route('tasks.store', ['id' => $project->id]) }}" method="POST">
@csrf
<div class="form-group">
<label for="name">Nome da tarefa</label>
<input name="name" type="text" class="form-control" id="name" placeholder="Nome">
</div>
<div class="form-group">
<label for="description">Descrição da tarefa</label>
<textarea name="description" type="Description" class="form-control" id="description" placeholder="Descrição"></textarea>
</div>
<div class="form-group">
<label for="difficult">Dificuldade</label>
<select class="form-control" name="difficult">
<option value="0">- Selecione -</option>
<option value="1">Fácil</option>
<option value="2">Média</option>
<option value="3">Difícil</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Sair</button>
<button type="submit" class="btn btn-primary">Cadastrar</button>
</div>
</form>
</div>
</div>
</div>
</div>
Task method of the TaskController class:
public function store(Request $request, $id)
{
$request->merge([
'project_id' => $id
]);
Task::create($request->all());
return back();
}
Error message:
"Too few arguments to function App\Http\Controllers\TaskController::store(), 1 passed and exactly 2 expected"