i have an input called id and i want to specify the button path for that id example:
in my blade file
<div >
<lable for="">ID:</lable><br/>
<input type="text" name="id" placeholder="Enter the product name" required><br/>
</div>
<div >
<button type="button" data-dismiss="modal">Close</button>
<button type="button" onclick="location.href='/produtos/editar/{{$id}}';" >Save changes</button>
</div>
Now my controler.php
public function update(Request $request, $id){
$produto=Produto::findOrFail($id);
$produto->update([
'id'=>$request->id,
'Nome'=>$request->nome,
'custo'=>$request->custo,
'preco'=>$request->preco,
'quantidade'=>$request->quantidade,
'Marca'=>$request->marcas,
'Voltagem'=>$request->Voltagem,
'Descricao'=>$request->Descricao,
]);
return " Produto Atualizado com Sucesso!";
}
now in routes file
Route::get('/produtos/editar/{id}', 'App\Http\Controllers\ProdutosController@edit');
Route::post('/produtos/editar/{id}', 'App\Http\Controllers\ProdutosController@update')->name('alterar_produto');
Being able to get the input value and put it along the route to the file
CodePudding user response:
You need to set post method for update data. You have onclick action on submit button, but your route method is POST. Therefore, your update procedure doesn't work. You need to change code with element, like that:
<form action="/produtos/editar/<?=$id?>" method="post">
<div >
<lable for="">ID:</lable>
<br/>
<input type="text" name="id" placeholder="Enter the product name" required><br/>
</div>
<div >
<button type="button" data-dismiss="modal">Close</button>
<button type="button" >Save changes</button>
</div>
</form>
CodePudding user response:
You need to use laravel form for that
{{ Form::open(array('action' => array('ProdutosController@update', $id), 'method' => 'POST')) }}
<div >
<lable for="">ID:</lable><br/>
<input type="text" name="id" placeholder="Enter the product name" required>
<br/>
</div>
<div >
<button type="button" data-dismiss="modal">Close</button>
<button type="submit" >Save changes</button>
</div>
{{ Form::close() }}