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