Filippo Bertilotti
2 days ago 0085dcb4e3ab76219819b8a53950df1261c04453
commit | author | age
42e9ce 1 <?php
FB 2 namespace App\Vola\Services\FakeSSODatabase;
3
7e64cc 4 use App\Models\Msisdn;
072cbb 5 use App\Models\Products;
2bfce6 6 use App\Models\VodafoneUser;
42e9ce 7 use Exception;
FB 8 use Illuminate\Support\Facades\DB;
6aea63 9 use PDOException;
42e9ce 10
FB 11 class FakeSSODatabaseHandler {
6aea63 12
FB 13     public function insertDataIntoTables(array $data) {
42e9ce 14         try{
885e76 15
FB 16
17             $userModel = VodafoneUser::create(['Name' => $data["Name"],
18                                                'Surname' => $data["Surname"],
19                                                'EmailAddress' => $data["EmailAddress"]]);
fcae3d 20             $msisdnModel = Msisdn::create(['MSISDN' => $data["sim_1"],
FB 21                                            'IdPiano' => $data['IdPiano'],
22                                            'LinkedUser' => $userModel->id]);
c52de0 23
FB 24             foreach ($data["products_select"] as $index => $value) {
25                 $product = Products::find($value);
26                 $product->msisdn()->attach($msisdnModel->id);
27             }
28
29
6aea63 30         }catch(PDOException $e) {
FB 31             echo $e->getMessage();
2bfce6 32         }
FB 33
42e9ce 34     }
FB 35
072cbb 36     public function readProducts(): array {
FB 37         $productsList = Products::select("Name", "id")->get()?->toArray();
38         return $productsList;
c52de0 39     }
42e9ce 40 }