Php 控制器laravel中的阵列
有人能帮我修改代码吗?我有这个概念,但不知道如何将它们写入控制器的代码中Php 控制器laravel中的阵列,php,arrays,laravel,laravel-5.2,Php,Arrays,Laravel,Laravel 5.2,有人能帮我修改代码吗?我有这个概念,但不知道如何将它们写入控制器的代码中 $temp=DB::table('temporary')->get(); //dd($temp); if($temp['tahun'] < 'current year'){ $temp['tahun'] = 'current year'; $temp['nomor'] = 'nomor+1'; $keluhan->no_laporan =
$temp=DB::table('temporary')->get();
//dd($temp);
if($temp['tahun'] < 'current year'){
$temp['tahun'] = 'current year';
$temp['nomor'] = 'nomor+1';
$keluhan->no_laporan = $temp['nomor'];
} else {
$temp['nomor']++;
}
$temp=DB::table('temporary')->get();
//dd($temp);
如果($temp['tahun']<'current year'){
$temp['tahun']=“本年度”;
$temp['nomor']='nomor+1';
$keluhan->no_laporan=$temp['nomor'];
}否则{
$temp['nomor']++;
}
条件:
我的临时表有2个属性tahun(value=2017 int)和nomor(value=1 int)
我想检查我的tahun是否<当前年份(实时年份,idk代码,所以我写当前年份),然后我的tahun变成=当前年份,我的nomor++(首先是它的值+1),我如何将它们写入laravel代码?请帮忙,谢谢你,伙计$temp=DB::table('temporary')->get()代码>将获得一个集合。所以你必须循环。并使用它来获取日期
foreach($temp as $temp)
{
if($temp->tahun < Carbon\Carbon::now()->year){
{
$temp->tahun=Carbon\Carbon::now()->year;
$temp->nomor=$temp->nomor+1;
$temp->update();
}
else
{
$temp->nomor=$temp->nomor+1;
$temp->update();
}
}
foreach($temp作为$temp)
{
如果($temp->tahun年){
{
$temp->tahun=Carbon\Carbon::now()->year;
$temp->nomor=$temp->nomor+1;
$temp->update();
}
其他的
{
$temp->nomor=$temp->nomor+1;
$temp->update();
}
}
DB::table('temporary')->->->get()将返回一个集合。从您的代码来看,您似乎在处理单个列,您可以使用first()
对于日期,可以使用简单的date()函数
$temp=DB::table('temporary')->first();
//dd($temp);
if($temp->tahun < date("Y")){
$temp->tahun = date("Y");
$temp->nomor++;
$keluhan->no_laporan = $temp->nomor;
} else {
$temp->nomor++;
}
$temp=DB::table('temporary')->first();
//dd($temp);
如果($temp->tahun<日期(“Y”)){
$temp->tahun=日期(“Y”);
$temp->nomor++;
$keluhan->no_laporan=$temp->nomor;
}否则{
$temp->nomor++;
}
代码中的变量$keluhan
是什么?当您可以使用date('Y')
@fubar Carbon是laravel的一个内置功能,并且更容易理解。使用date()
我们必须处理strotime
、格式问题、大量计算等等。碳在Laravel中是一个依赖项,它不是内置的。使用date('Y'))
要获得当前年份,您不需要使用strotime
,也不需要进行任何计算。好的。谢谢您提供的信息。我会学习并确保它。感谢大家现在帮助它工作,太好了。上帝保佑你们。