The question has been asked more than once in the community, but I’m interested in the details rather than the solution itself. So, the situation is ordinary: there are tables
- Users (ID, name)
- Cards (ID, number)
- User_cards (user_id, card_id)
There is a form in which an excel file is selected, in which there are two columns: the full name, the number of the card and such records, say, 10,000 in this file.
And now the actual question: how best to implement checks:
- A user with the same name exists in the Users table.
- A card with this number exists in the Cards table.
I understand that this can be done through ordinary Eloquent
// ищем пользователя по ФИО User::where('name', $userName)->first(); // ищем карту по номеру Card::where('number', $cardNumber)->first();
But. If we were talking about pure PHP, then I would use the Prepared Statement to reduce the load on the database server, and this results in a lot of queries of the same type without saving.
To parse the excel itself, I use Laravel Excel. https://laravel-excel.com/ I put such work in the background, in Jobs, in the queue, but I still don’t understand how to work with prepared expressions in Laravel. I use MySQL 5.0.11 as a DBMS.