0
good morning, someone can help me in this select, (example: User will register and there he selects the customer already registered).
then you will have the inputs to fill but select, OK!
now it will change the form, as I can bring the selected value
edit.blade.php
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h2>Alterar Apontamento</h2>
</div>
<div class="card-body">
<form action="{{route('equipe.alterar.apontamento', ['id' => $apontamento->id])}}" method="post">
@csrf <!--protecao-->
@method('put')
<div class="form-group">
<label for="cliente">Cliente</label>
<select name="cliente" id="cliente" class="form-control" >
<option value="" selected>Selecione</option>
@foreach($clientes as $cliente)
<option value="{{$cliente->id}}">{{$cliente->user->name}}</option>
@endforeach
</select>
@error('cliente')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="servicos">Serviços</label>
<select name="servicos" id="servicos" class="form-control">
<option value="" selected>Selecione</option>
@foreach($servicos as $servico)
<option value="{{$servico->id}}">{{$servico->nome}}</option>
@endforeach
</select>
@error('servicos')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="inicio">Hora inicio:</label>
<input type="text" class="form-control" name="inicio" id="inicio" value="{{$apontamento->inicio}}">
@error('inicio')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="termino">Término:</label>
<input type="text" class="form-control" name="termino" id="termino" value="{{$apontamento->termino}}">
@error('termino')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="considerado">Considerado:</label>
<input type="text" class="form-control" name="considerado" id="considerado" value="{{$apontamento->considerado}}">
@error('considerado')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="atividade">Atividade:</label>
<input type="text" class="form-control" name="atividade" id="atividade" value="{{$apontamento->atividade}}">
@error('atividade')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
<label for="observacao">Observação</label>
<textarea type="text" rows="6" class="form-control" name="observacao" id="observacao" value="{{$apontamento->observacao}}"></textarea>
@error('observacao')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
</div>
<button class="btn btn-primary">Alterar</button>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
controller
public function edit($id)
{
$apontamento = Apontamento::with('user')->where('id', $id)->first();
return view('apontamento.editar', compact('apontamento'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$apontamento = Apontamento::find($id);
$clientes = Cliente::find();
$servicos = Servicos::find();
$apontamento->atividade = $request->atividade;
$apontamento->inicio = $request->inicio;
$apontamento->termino = $request->termino;
$apontamento->considerado = $request->considerado;
$apontamento->observacao = $request->observacao;
$clientes->cliente_id = $request->cliente;
$servicos->servico_id = $request->servicos;
$apontamento->save();
return redirect()->back();
}
see if my controller is right..
– user160990
can, changed controller $clients = Client:::all();
– user160990
@Fernandosqse did not understand
– novic
it worked rsrsrs
– user160990
So if it’s useful @Fernandosqse signal as an answer to your question
– novic