Filippo Bertilotti
2024-07-31 7e64cc10b90638803aa7e6b1b78c76825a8da866
relazione fra 2 record (vodafoneuser e msisdn)
6 files modified
33 ■■■■■ changed files
app/Models/Msisdn.php 8 ●●●●● patch | view | raw | blame | history
app/Models/VodafoneUser.php 2 ●●● patch | view | raw | blame | history
app/Vola/Services/FakeSSODatabase/FakeSSODatabaseHandler.php 18 ●●●● patch | view | raw | blame | history
database/migrations/2023_05_02_170505_create_fakesso_products.php 1 ●●●● patch | view | raw | blame | history
database/migrations/2023_05_02_170506_create_fakesso_vodafoneusers.php 1 ●●●● patch | view | raw | blame | history
database/migrations/2023_05_02_170537_create_fakesso_msisdn.php 3 ●●●● patch | view | raw | blame | history
app/Models/Msisdn.php
@@ -8,29 +8,31 @@
class Msisdn extends Model
{
    protected $table = "fakesso_msisdn";
    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'VodafoneUser',
        'MSISDN',
        'CardType',
        'IdPiano',
        'VodafoneOne',
        'TopClub',
        'SeniorityCluster',
        'LinkedUser'
    ];
    public function user()
    {
        return $this->belongsTo('App\Models\VodafoneUser', 'VodafoneUser', 'id');
        return $this->belongsTo(VodafoneUser::class, 'LinkedUser');
    }
    public function products()
    {
        return $this->belongsToMany('App\Models\Products', 'pivot_msisdn_products', 'idProducts', 'idMsisdn');
        return $this->belongsToMany(Products::class, 'pivot_msisdn_products', 'idProducts', 'idMsisdn');
    }
}
app/Models/VodafoneUser.php
@@ -37,7 +37,7 @@
    public function sims()
    {
        return $this->hasMany('App\Models\Msisdn','VodafoneUser', 'id');
        return $this->hasMany(Msisdn::class,'LinkedUser', 'id');
    }
}
app/Vola/Services/FakeSSODatabase/FakeSSODatabaseHandler.php
@@ -1,6 +1,7 @@
<?php
namespace App\Vola\Services\FakeSSODatabase;
use App\Models\Msisdn;
use App\Models\VodafoneUser;
use Exception;
use Illuminate\Support\Facades\DB;
@@ -8,20 +9,27 @@
class FakeSSODatabaseHandler {
    public function __construct() {
    }
    public function insertDataIntoTables(array $data) {
        $user =
        $userArray =
        [
            'Name' => $data["Name"],
            'Surname' => $data["Surname"],
            'EmailAddress' => $data["EmailAddress"]
        ];
        $msisdnArray =
        [
            'MSISDN' => $data["sim_1"],
            'IdPiano' => $data["IdPiano"]
        ];
        try{
            VodafoneUser::insert($user);
            $userModel = VodafoneUser::create($userArray);
            Msisdn::create(['MSISDN' => $data["sim_1"],
                            'IdPiano' => $data['IdPiano'],
                            'LinkedUser' => $userModel->id]);
        }catch(PDOException $e) {
            echo $e->getMessage();
        }
database/migrations/2023_05_02_170505_create_fakesso_products.php
@@ -20,6 +20,7 @@
            $table->string('Name', 255)->nullable();
            $table->string('Description', 255)->nullable();
            $table->string('activationDateTime', 255)->nullable();
            $table->timestamps();
        });
    }
database/migrations/2023_05_02_170506_create_fakesso_vodafoneusers.php
@@ -29,6 +29,7 @@
            $table->string('MicroBusiness', 255)->nullable();
            $table->string('HomePhone', 255)->nullable();
            $table->string('Address', 255)->nullable();
            $table->timestamps();
        });
    }
database/migrations/2023_05_02_170537_create_fakesso_msisdn.php
@@ -16,7 +16,8 @@
            $table->string('IdPiano', 255)->nullable();
            $table->string('VodafoneOne', 255)->nullable();
            $table->string('TopClub', 255)->nullable();
            $table->string('SenioriryCluster', 255)->nullable();
            $table->string('SenioriryCluster', 255)->nullable();
            $table->timestamps();
        });
    }