Change the value in the table when you make a new record?

I write the dialogue, such a poser:
There is a function to hide the dialog, which changes the value in the database the column is 1 hide(hidden), and actually not displayed.
If the user(who have hid, and not hid ) will write to those who have concealed - dialog will appear.
I have zagvostka, I have 2 tables:
messages (Here are stored all the dialogues) and users_in_dialogs (id, user_id, dialog_id, actually hide)
I make a request to the messages table, check the ID of the dialogs(like "dialog_id =". $dialog_id (I have a little bit different, pure essence) and to make selections from table readed(0 - unread, 1 - read)
Then write the check: if ($variable where the value is stored readed == 0) {
then I call the function dialogs(to output) and do the update value to Hide
Only nicherta not plow
Piece function hideDialog, the little formalities + catch
$data = Input::all();

 //need dialog_id
 try {


 ->where('dialog_id', '=', $data['dialog_id'])
 ->where('user_id', '=', $this->user->id)
 ->update([ 'hide' => 1 ]);

And here is the piece of code function showDialog()
below small formalities
$data = Input::all();
 $dialogreaded = DB::table('messages')
 ->where('dialog_id = '.$data['dialog_id'])

 if ($dialogreaded == 0){
 return getDialogs(); // the Function that displays the dialogue on the page
 ->update(['hide' => 0]);

P. S: everything works angulare and everything else works ofks, the only problem with this(
Function hide pass in angular course, as in a clique is hiding
July 9th 19 at 11:16
1 answer
July 9th 19 at 11:18
as far as I understood from the dialogue hides problems from You, there is a problem with how it displays in the publication of reports by users. In that case, why would it just not implemented on the trigger when adding messages? something like:
UPDATE users_in_dialogs SET hide = 0 WHERE users_in_dialogs.dialog_id = new.gialog_id AND hide = 1;
Thanks, I'll try)
I only delve into PHP, parse the code now, so have not heard about it( - raymundo.Veum commented on July 9th 19 at 11:21

Find more questions by tags MySQLPHP