0

In my laravel + vue application I am trying to update the name and account_external_id column in mysql database.

Here is the code:

// Set the database name and id project
$db_name = $get_db->mysql_db_name;
$id_project = $get_db->id_project;

// Update linked account
$update_linked_account = DB::connection($db_name)
->table($db_name . '.linked_accounts')
->where('id_linked_account', $id_linked_account)
->where('id_project', $id_project )
->update([
    'name'  =>  $account_name, 
    'account_external_id'   =>  $account_id
]);
                
// If updated
if( $update_linked_account ) {
    return response()->json([
        'success'   =>  true, 
        'message'   =>  'Account updated successfully.'
    ], 200);
} else {
    return response()->json([
        'success'   =>  false, 
        'message'   =>  'Could not update the account.'
    ], 200);
}

When I change the name or account_external_id value then press the update button then I can get the $update_linked_account as true.

BUT

When I do not change the name or account_external_id value then press the update button then I can get the $update_linked_account as false. why? It should give me true too, right?

Shibbir
  • 1,963
  • 2
  • 25
  • 48
  • 1
    Yes, I understand why its not showing me true and now I have change my way to show message to the user. Thanks anyway. – Shibbir Dec 15 '22 at 08:04
  • [MySQL update not updating](https://stackoverflow.com/questions/12376733/mysql-update-not-updating) – steven7mwesigwa Dec 15 '22 at 08:06
  • For `->update(...)` and `->delete(...)` calls, the return value is the [*number of affected rows*](https://stackoverflow.com/a/33462806/7376590). – steven7mwesigwa Dec 15 '22 at 08:27

0 Answers0