I have a field in my database which has a datetime type column. I want that field to have today's date every time the view is loaded. Can I do this with AJAX and the location.reload()
function?

- 3,541
- 28
- 38
- 38

- 887
- 2
- 17
- 29
-
Yes. You can do this with Ajax. Let the down voting begin... – suchislife Mar 06 '18 at 10:12
-
and why is that ? – Youssef Boudaya Mar 06 '18 at 10:13
-
No example, no effort, the usual... – suchislife Mar 06 '18 at 10:14
-
ah okay thank you for your big help – Youssef Boudaya Mar 06 '18 at 10:14
-
1Hi @YoussefBoudaya, you've been here long enough, you should have read the [tour] and [ask] by now. You might also like to read: https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users – freedomn-m Mar 06 '18 at 10:18
-
Guys you get his point so dont be sally just answer him if you want – Ahmed Shams Mar 06 '18 at 10:20
2 Answers
Here's some pseudo logic...
- You database field is likely to belong to a database table row.
- This database table row hopefully has a primary key.
- Each time your page loads, you get this primary key, and run an UPDATE query on the datetime field to now() corresponding to it.
Here's another resource with possible examples:

- 4,251
- 10
- 47
- 78
-
okay already began trying after your comment hope i'll get it right. i asked the question because i'm not excellent in developpement so i figured it will take me a long time to find the result thanks anyway. – Youssef Boudaya Mar 06 '18 at 10:23
-
I've added a link to a similar question here on stackoverflow containing examples for you as well. – suchislife Mar 06 '18 at 10:25
Ok first for ADVICE just before you hit ASK Question learning about how you searching about your problem then you wont see sally people says "learn how to ask" or "Vote Down"
second you should create function in your controller that make update the database time i use Carbon library its builtin in laravel and its very cool just import it
use Carbon\Carbon;
your controller function
public function UpdateDate(){
$time=Carbon::now();
$time->timezone = 'Europe/Athens';
$UpdateNewDate=$time->format('Y-m-d');// choose the format you wanna
//if you working with model so do model update by save()
//if you dont use DB::update('');
$InsertedDate=DB::update('update blablabla set ColumnName=?' where blabla=2,[$UpdateNewDate]');
if($InsertedDate){
return response()->json([
'Status'=> true,
'Message'=>'Updated',
'Data' => null,
], 200);
}
else //check the error
}
then in Route web or api as you working on refere to your controller by post and i hope you know about auth you should make auth about any one inserted to DB or updated or select
Route::post('/UpdateDate','YourControllerName@UpdateDate');
in your blade view
$.ajax({
method: 'POST',
dataType: 'json',
url: "http://localhost/LaravelProject/public/UpdateDate",
data: null,
success: function(data){
console.log('succes: '+data['Success']);
}
});
then check your console by inspect if you see True then you are welcome if not contact me and you are welcome any way
mt5lesh 7d y2ll menk do your best ya sde2y :D

- 338
- 1
- 9