dimanche 3 février 2019

After deleted this table row, update another table specify columns in laravel

As you see below i have two table.

1.Posts Table (record the in and out of the table)

id  lecture_name    roomkey created_at  updated_at  user_id
1   Ee Vonne Ng     L02     2019-01-22  2019-02-03      1
2   Ee Vonne Ng     L03     2019-01-22  2019-01-23      1

2.key table (keynos)

id  roomkey status  created_at  updated_at
1   L01     0       2019-01-22  2019-02-04 
2   L02     1       2019-01-22  2019-01-22 
3   L03     1       2019-01-22  2019-01-22 
4   L04     0       2019-01-22  2019-02-04 

I am having a problem as when i want to delete a record in posts,yes,i am successful, but i want it to update also the keyno status to 0, so that it act as this key is active. But i don't know what have i missed as i can delete but i can't update the keyno status. No error is show, but my status is not update. How anyone can help me or give me some advise TT

Below is my code.

1=Key in use 0=not in use

1.Post controller

 */
public function destroy($id)
{
    $post =  Post::find($id);
    $post->delete();
    if($post->delete()){
        $post = Post::find($id);
        $key = Keyno::all();

        $postroomkey = $post->roomkey;
        Keyno::where('roomkey','=',$postroomkey)
        ->update(['status' => 0]);
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire