简体   繁体   中英

How to compare user input with the data in the database laravel

I have an input field and would like to compare the data wich got sent with those in my database.

Suppose we have a book with a serial number. Now this customer borrows this book and wants to return it after one week. Then he verifies himself with his membership card and sees a table where his borrowed books are listed. Before he can return the book he has to scan the serial number of this book. This is to compare whether the serial number is really in the database.

And this is exactly what I'm looking for help with, everything else I've implemented so far, and with the help of this community I'd like to thank everyone again.

Now I need your help again how I could implement this check. I think I could solve it somehow in the controller with an if statement but don't know how to implement it correctly.

My Controller function:

    public function verify(AusleihRequest $request){

   $this->middleware('guest');

   $validator = Ausleih::make($request->all(), [
     'seriennummer' => 'required'
   ]);








     return redirect()->route('ausleihe.yourdevices')
                      ->with('success','Gerät erfolgreich verifiziert');


 }

EDIT:

And the user shouldnt had to log in again after verifying.

Use the exists rule:

The first param after the : specifies the name of your table, the second (after the , ) the name of the field, the number is stored.

$validator = Ausleih::make($request->all(), [
  'seriennummer' => 'required|exists:serialnumbers,number' // or however your field is named
]);

https://laravel.com/docs/master/validation#rule-exists

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM