-1
I have a view q shows a user’s access key, in it I need to press a button q will update the access key randomly, the update returns to the view but does not modify the key. How can I fix this?
Controller update:
public function update(User $api)
{
//Cria chave e veriica a existencia no banco de dados
$permitted_chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$hash = substr(str_shuffle($permitted_chars), 0, 40);
$validator = \Validator::make(['hash' => $hash], ['hash' => 'unique:users,api_access_Key']);
if ($validator->fails()) {
return $this->randomId();
}
//fim
$api->update([
'api_access_key' => $hash,
]);
return redirect()->route('user.index');
}
controller index:
public function index(User $model)
{
$id = Auth::user()->id;
$userIndex = DB::select("select * from users where id = '$id'");
return view('apis.API', compact('userIndex'));
}
as I call the method on the button:
<a href="{{ route('api.update', $api) }}" class="btn btn-primary">{{ __('Nova chave') }}</a>
Try to give a
save
after update:$api->update([
 'api_access_key' => $hash,
 ])->save();
– Kayo Bruno
return $this->randomId();
What is this? Is it a method? Is he not going there ?– novic
Return $this->randomId():, if the key already exists in the database the script is run again through this Return.
– aguiar677