ali_254 Posted August 12, 2021 Share Posted August 12, 2021 I want to add a value to the field, and keep the previous value in the field.How does it work? $data['count'] = 1; DB::table('posts')->where('id' , $id)->update($data); Quote Link to comment https://forums.phpfreaks.com/topic/313541-add-a-number-to-the-record/ Share on other sites More sharing options...
requinix Posted August 12, 2021 Share Posted August 12, 2021 You can't both change and not-change the value. Explain what you're trying to do in more detail. 1 Quote Link to comment https://forums.phpfreaks.com/topic/313541-add-a-number-to-the-record/#findComment-1589071 Share on other sites More sharing options...
ali_254 Posted August 12, 2021 Author Share Posted August 12, 2021 (edited) ok thanks.... I want to get the number of views of an posts(Articles). I created a field in the posts table, I want to add a value to the field every time the code is executed. As a result, I have to update the value of a field , By maintaining the previous value that exists in the database. i want update a field , By maintaining the previous value DB::table('posts')->where('id' , $id)->update($data); Edited August 12, 2021 by ali_254 Quote Link to comment https://forums.phpfreaks.com/topic/313541-add-a-number-to-the-record/#findComment-1589072 Share on other sites More sharing options...
requinix Posted August 12, 2021 Share Posted August 12, 2021 So you want a query like UPDATE posts SET count = count + 1 WHERE id = $id 1 Quote Link to comment https://forums.phpfreaks.com/topic/313541-add-a-number-to-the-record/#findComment-1589073 Share on other sites More sharing options...
ali_254 Posted August 12, 2021 Author Share Posted August 12, 2021 (edited) 53 minutes ago, requinix said: So you want a query like UPDATE posts SET count = count + 1 WHERE id = $id ok thanks , but this procedure use in 'Pure PHP' ! . i want update database in laravel framework and this Command Will not work! i use from query builder in laravel Edited August 12, 2021 by ali_254 Quote Link to comment https://forums.phpfreaks.com/topic/313541-add-a-number-to-the-record/#findComment-1589074 Share on other sites More sharing options...
requinix Posted August 12, 2021 Share Posted August 12, 2021 Yes, it is possible to make that query happen with the query builder. Have you looked around to see what kinds of options you have available to use? 1 Quote Link to comment https://forums.phpfreaks.com/topic/313541-add-a-number-to-the-record/#findComment-1589075 Share on other sites More sharing options...
ali_254 Posted August 13, 2021 Author Share Posted August 13, 2021 thanks... we can use from this cod: DB::table('posts') ->where('id' , $id) ->increment('counter', 1); Quote Link to comment https://forums.phpfreaks.com/topic/313541-add-a-number-to-the-record/#findComment-1589076 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.