mercredi 30 juin 2021

it doesn't take my password set in a variable

i need help to know why my static password saved in variable does not work

I'm doing is deleting records, but with a password to confirm the action

enter image description here

Controller:

public function eliminar($id) {
    $registros = \App\Models\Registro::find($id);
    if (! $registros) {
        session()->flash('error_message', 'Model not found with the given id:');
        return back();
    }

    // static password
    $password = ('asdf');

    // $password is the password that you have saved somewhere
    if (request()->password_field_value == $password) {
       
        $registros->delete();
        
        session()->flash('success_message', 'Model deleted successfully.');
        return back();
    }

    session()->flash('error_message', 'Invalid password. Try again');
    return redirect('sistema');
}

blade

@extends('layouts.app')
    
@section('content')
    <h1>Do you want to delete the record?</h1>
    <form action="" class="d-inline" method="POST">
        @method('DELETE')
        @csrf
        <button type="submit" class="btn btn-danger btn-sm">DELETE</button>
        <div class="form-group col-md-6">
            <label for="telefono">Password</label>
            <input name="password" type="password" class="form-control" id="password"  required>
        </div>
    </form> 
@endsection

I need to know why it always throws an error, Invalid password. Try again

help please



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire