1
Hello,
I have a table with the following fields:KEY, VALUE , ALIAS, CLIENT_ID.
In a certain system process I need to update Key and Value.
To update a record I have no problems, the problem is that when I need to change two KEYS and two VALUES of a client ID I am using the update function of the Laravel/repositories, then the code was like this:
public function update(Request $request, $id)
{
$this->client->update($request->all(), $id);
}
The problem is that with this method if I have 2 values and 2 Keys, it overrides the first so what I get is just
request = [ key => 'segundo valor do form', value => 'segundo valor do form'];
I need the 2 Keys and the 2 values. Can anyone help?
Using Repository? 2 values and 2 Keys from input? only if using
array. Thuskey[] =1&key[]=2– Wallace Maxters
I did with Repository because it’s the only way I know how to do it, but if there’s another way, without using Repository, I can/can use it.
– Ivan Moreira
I only use Laravel without Repository. Respository is for something very specific, such as the need to change your Orm. I think Laravel’s ORM is already quite potent.
– Wallace Maxters
How the update would look using the ORM ?
– Ivan Moreira
This is actually the Controller’s method, right? Why are you passing
Request. In fact, you need to explain how two values will come in Keys and Values. This comes from the form?– Wallace Maxters
The normal ORM update is
Cliente::where(['id' => $id])->update(['nome' => 'Nome', ' endereco' => 'Rua blablala']).– Wallace Maxters
The form is built like this: {!! Form::open(array('method'=>'put', 'url' => url())) !! } @foreach() <div class="input-group" style="margin-top: 10px"> {!! Form::Hidden('key', $key) !! } {!! Form::text('value', '')) !! } <button> Submit</button> @endforeach {!! Form::close() !!}
– Ivan Moreira
@Ivanmoreira can you explain your problem better? do you want to update several lines of your database right? so are you getting more of an id or did I get the problem wrong? add more details and code please.
– Rafael Berro
@Rafaelberro The problem has been fixed, I used the answer below and I foreach the controller to receive 1 or more keys.
– Ivan Moreira
@Ivanmoreira Great, you should select it as the solution to your question.
– Rafael Berro