jhutto
362
6
General

Access array variable for inserting into sql table.

Posted 10 months ago by jhutto

I know this is a simple question and I should already know the answer but here it is....

I have an ajax call to a controller but I can't figure out how to access the array variable being created from a query call.

What am I doing wrong.. .And I know it's something simple.

This line is not getting inserted into the table. 'NameCounter' => $assistant->get('NameCounter'),

I have tried... 'NameCounter' => $assistant['NameCounter'], 'NameCounter' => $assistant['0']['NameCounter'],

 public function courseasstAjax($casstID, $courseID)
    {

             
        //Get NameCounter from Table of Course Assistants
        $assistant = DB::table('courseassistants')
        ->where('id', '=' , $casstID)
        ->get();
        
       
        //Create new record in SOMASCOURSEAssistants Table
        SOMASCourseAssistant::create([
             'ClassID' => $courseID,
              'NameCounter' => $assistant->get('NameCounter'),
          ]);
        
     
        
      return json_encode($assistant);

    

    }

I know the query is working because I can get it to return the array values in json....

[{…}]
0: {id: 7, NameCounter: 1649, FirstName: "Connie R", LastName: "Gabriel", Salutation: "Connie", …}
length: 1
__proto__: Array(0)

Please sign in or create an account to participate in this conversation.