Support the ongoing development of Laravel.io →
Database Eloquent

TL;DR: Eloquent models are updating, if I dump the object the attributes show correctly, but when I query the DB it is not correct. Code:


public function store(Requests\CreateDIDRequest $request)
{
    Log::info("Starting DID creation");
    $DIDs = [];
    switch($request->input('did_quantifier'))
    {
        case 'list':
            Log::info("List of DIDs given");
            $raw = preg_split ("/\\r\\n|\\r|\\n/", $request->input('did_list'));
            foreach($raw as $did)
            {
                preg_match('/\d{10}/',$did,$match);
                $DIDs[] = $match[0];
            }
            break;
        case 'range':
            Log::info("Range of DIDs given");
            for($i=$request->input('did_range_start'); $i<=$request->input('did_range_end'); $i++)
            {
                $DIDs[] = $i;
            }
            break;
    }
    Log::info("Iterating through DIDs");
    foreach($DIDs as $tmpDID)
    {
        Log::info("Building {$tmpDID}");
        $newDID = DID::firstOrCreate(['did' => $tmpDID]);

        if($request->input('customer_id') != '0')
        {
            Log::info("{$tmpDID}: Assigning DID");
            $data = [
                'customer_id' => $request->input('customer_id'),
                'service_location_id' => $request->input('service_location_id'),
                'name' => $request->input('name'),
                'address' => $request->input('address'),
                'address2' => $request->input('address2'),
                'city' => $request->input('city'),
                'state' => $request->input('state'),
                'zip' => $request->input('zip'),
                'inuse' => '1',
                'flhsi_tn' => '1',
                'did_network_id' => $request->input('did_network_id')
            ];                
        }else
        {
            Log::info("{$tmpDID}: Not assigning DID");
            $data = [
                'inuse' => '0',
                'flhsi_tn' => '1',
                'did_network_id' => $request->input('did_network_id')
            ];
        }
        Log::info("{$tmpDID}: Data:");
        Log::info($data);
        $newDID->update($data);
        if(!$newDID->ratecenter)
        {
            $newDID->updateRateCenter();
        }

        $IncomingExtension = CVRExtension::firstOrCreate([
            'context' => 'incoming-direct',
            'exten' => $tmpDID,
            'priority' => '1'
        ]);
        $OutgoingExtension = CVRExtension::firstOrCreate([
            'context' => 'outbound',
            'exten' => $tmpDID,
            'priority' => '1'
        ]);
        $IncomingExtension->update(['app' => 'Goto','appdata' => 'incoming-unused,s,1']);
        $OutgoingExtension->update(['app' => 'Goto','appdata' => 'incoming,${EXTEN},1']);
    }

    //return redirect("/did");
}

As far as the DB goes, it looks like no query happens after the initial firstOrCreate, data is not updated at all on the DID model, but the CVRExtensions are created and updated correctly. Trying to find out why it isn't persisting the data to the DB.

Last updated 3 years ago.
0

Got my answer from another forum. If interested, link below.

https://redd.it/63l8zf

0

Sign in to participate in this thread!

Eventy

Your banner here too?

rberlin01 rberlin01 Joined 5 Sep 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.