我的数据库中有一个具有日期时间类型列的字段。我希望每次加载视图时该字段都有今天的日期我可以使用ajax和location.reload()函数吗?
答案 0 :(得分:1)
这里有一些伪逻辑......
这是另一个有可能示例的资源:
答案 1 :(得分:1)
在您点击ASK之前先咨询ADVICE问题了解您如何搜索问题然后您不会看到Sally人说“学会问”或“投票”
第二 您应该在控制器中创建更新数据库时间的函数 我使用其内置于laravel的Carbon库,非常酷,只需导入它
use Carbon\Carbon;
您的控制器功能
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
}
然后在Route web或api中,当您通过邮寄方式参考您的控制器时,我希望您了解auth,您应该对任何插入数据库或更新或选择的人进行认证
Route::post('/UpdateDate','YourControllerName@UpdateDate');
在您的刀片视图中
$.ajax({
method: 'POST',
dataType: 'json',
url: "http://localhost/LaravelProject/public/UpdateDate",
data: null,
success: function(data){
console.log('succes: '+data['Success']);
}
});
然后通过检查您的控制台是否看到True然后欢迎您,如果没有联系我,欢迎您,
mt5lesh 7d y2ll menk尽你所能ya sde2y:D