ottaviane
6 months ago

saving record " ErrorException (E_NOTICE) Array to string conversion"

Posted 6 months ago by ottaviane

Hi all. I have to save record in a table but I receive this error message: " ErrorException (E_NOTICE) Array to string conversion"

This is code:

public function store(Request $request)
    {
        //aggiungi un record
        $id_tab=request(['id_tab']);
        $id_canto=$request['canti'];
        $tab=new SpartInRacc;//new instance of my model
        $tab->setTable($id_tab);
        $tab->id_canto=$id_canto;
        $tab->save();        
        return redirect('/spartinracc');
    }

and dd($tab); outs

    SpartInRacc {#244 ▼
  #table: array:1 [▼
    "id_tab" => "13-Natale"
  ]
  #fillable: array:1 [▼
    0 => "id_canto"
  ]
  #connection: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #attributes: array:1 [▼
    "id_canto" => "22"
  ]
  #original: []
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▼
    0 => "*"
  ]
}

dd($id_canto); outs

"22"

where is the mistake? Bye

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