convert Christian calendar to shamsi - laravel

i want convert date and time to persian calendar with this package :
https://github.com/hekmatinasser/verta/
this package convert to shamsi but in for loop doesnt work,
this code is run:
return new Verta($show[$i]['created_at']);
in this code show date and time to pesrian date time format
but this code doesnt work:
$ishow['message'][$i]['time'] =new Verta($show[$i]['created_at']);
in this code show with christian date time format.
my main problem is in for loop show 'created_at' with chiristian format
how can i use it?

I am interested to try the library so I tested it and it's worked with New Verta($item->created_at) or Verta::instance($item->created_at). My code is like this:
foreach ($items as $item){
$shamsi[] = Verta::instance($item->created_at);
}
dd($shamsi);
It seems your $ishow is not updated from the old form. let's try code below:
$ishow = [];
foreach ($show as $item){
$ishow['message'][]['time'] = Verta::instance($item->created_at);
}
return $ishow;
or with for loop:
$ishow = [];
for ($i = 0; $i < count($show); $i++) {
$ishow['message'][$i]['time'] =new Verta($show[$i]['created_at']);
}
return $ishow;

Related

I can't get createdAt value form Parse(Back4App) by using PHP

Despite I use $object->getCreatedAt() function I cant fetch the createdAt column's values. Need help. Thanks in advance for all.
$tableFetch = new Database(); // This is my custom class structure
$subscriptions = $tableFetch->tableFetch("Subscribe");
for ($i = 0; $i < count($subscriptions); $i++) {
$object = $subscriptions[$i];
$createdAt = $object->getCreatedAt();
}
Edit: I can get the information of array but cant slice it with keys.
I found the answer.
After creating DateTime Object need to specify format as below.
$createdAt->format('Y-m-d H:i:s');

How to calculate between dates in Laravel + Vue js project

I am tired to calculate date with start & end date in my Laravel & Vue js project?
I have also installed moment js.
Code as below,
{{item.start_date | MyDate}}
{{item.end_date | MyDate}}
{{Here will be calculate between above dates}}
Please help me.
You can create new method with this logic:
methods: {
parseDate (start, end) {
return moment(start, 'YYYY.MM.DD HH:mm').diff(moment(end, 'YYYY.MM.DD HH:mm'), "days")
}
}
And in your template you can simply do that: {{ parseDate(item.start_date, item.end_date) }}
I think is that what you need. Here you can check some examples of using diff in moment.
Good luck!
If you are getting the data from Laravel you can use Carbon to calculate the difference like this:
$start_date = Carbon::parse($item->start_date);
$end_date = Carbon::parse($item->end_date);
$diff_in_hours = $end_date->diffInHours($start_date);
$diff_in_days = $end_date->diffInDays($start_date)
$diff_in_minutes = $end_date->diffInMinutes($start_date);
$diff_in_seconds = $end_date->diffInSeconds($start_date);
So if you are getting the data from a query you can map the query like this:
$schedules = DB::table('schedules')
->get()
->map(function($item){
$start_date = Carbon::parse($item->start_date);
$end_date = Carbon::parse($item->end_date);
$item->diff = $end_date->diffInMinutes($start_date);
return $item;
});
The same for models
Schedule::where('status',1)->get()
->map(function($item){
$start_date = Carbon::parse($item->start_date);
$end_date = Carbon::parse($item->end_date);
$item->diff = $end_date->diffInMinutes($start_date);
return $item;
});

Mass update in laravel using foreach

How to Update mass records without deleting or replacing old one inserted records. Here mine problem is that last inserted record will replace with latest records.
/*DB::table('syllabuses')
->where('course_id', $curse_id)
->Where('semster',$semesterid)
->delete();*/
$Syllabus = Syllabus::find($id);
foreach ($data as $value)
{
//$Syllabus = new Syllabus;//
$Syllabus->slno = $value->SlNo;
$Syllabus->coursecode =$value->cousrecode;
$Syllabus->coursename =$value->coursename;
$Syllabus->credit =$value->credit;
$Syllabus->papertype=$value->papertype;
$Syllabus->deptoffering_name=$value->Deptoffer;
$Syllabus->deptoffering_id=$value->Department;
$Syllabus->dept_id = $details['depart'];
$Syllabus->save();
}
Please try to understand the difference between INSERT and UPDATE first. Definitely update query replace the old values of the relevant record. In your query you are tying updating same "Syllabus".
$Syllabus = Syllabus::find($id);
foreach ($data as $value)
{
//$Syllabus = new Syllabus;//
$Syllabus->slno = $value->SlNo;
$Syllabus->coursecode =$value->cousrecode;
$Syllabus->coursename =$value->coursename;
$Syllabus->credit =$value->credit;
$Syllabus->papertype=$value->papertype;
$Syllabus->deptoffering_name=$value->Deptoffer;
$Syllabus->deptoffering_id=$value->Department;
$Syllabus->dept_id = $details['depart'];
$Syllabus->save();
}
In above code, you find the Syllabus outside of the foreach. Then you update the that found record inside the foreach. If you want to update many "Syllabus", then try this:
foreach ($data as $value)
{
$Syllabus = Syllabus::find("SyllabusID");
$Syllabus->slno = $value->SlNo;
$Syllabus->coursecode =$value->cousrecode;
$Syllabus->coursename =$value->coursename;
$Syllabus->credit =$value->credit;
$Syllabus->papertype=$value->papertype;
$Syllabus->deptoffering_name=$value->Deptoffer;
$Syllabus->deptoffering_id=$value->Department;
$Syllabus->dept_id = $details['depart'];
$Syllabus->save();
}
Or else, if you want to remain old records, please try to create new records in db using following code
foreach ($data as $value)
{
$Syllabus = new Syllabus();
$Syllabus->slno = $value->SlNo;
$Syllabus->coursecode =$value->cousrecode;
$Syllabus->coursename =$value->coursename;
$Syllabus->credit =$value->credit;
$Syllabus->papertype=$value->papertype;
$Syllabus->deptoffering_name=$value->Deptoffer;
$Syllabus->deptoffering_id=$value->Department;
$Syllabus->dept_id = $details['depart'];
$Syllabus->save();
}
Read official laravel documentation for further details: https://laravel.com/docs/5.7/eloquent

error foreach in View Codeigniter : Illegal string offset

Please help, i use foreach to return data from database, but it only return the last data (array always update with last data). So i modified the code but i got error : Illegal string offset in foreach.
here is my controller
foreach($dataDesa as $desa)
{
$namaDesa = json_decode($this->curl->simple_get($desa->alamat_api.'/info_desa?ID_DESA=1'));
$datakonten[$namaDesa] = array(
'proyek' =>json_decode($this->curl->simple_get($desa->alamat_api.'/proyek_pertanian')),
'nama_desa' =>json_decode($this->curl->simple_get($desa->alamat_api.'/info_desa?ID_DESA=1')),
'lelang' =>json_decode($this->curl->simple_get($desa->alamat_api.'/pelelangan'))
);
}
$datakonten['getAllDesa'] = $this->M_desa->getAllDesa($idStatus);
$nama_Desa = array();
foreach($datakonten['getAllDesa'] as $row)
{
$nama_Desa[] = $row->nama_desa;
}
$datakonten['nama_desa']=$nama_Desa;
$data['content'] = $this->load->view('public/konten/v_home',$datakonten,TRUE);
$this->load->view('public/halaman/v_home',$data);
and here is my view
$i=0;
foreach($nama_desa[$i]['proyek'] as $rows)
{
$nama = $rows->nama_proyek;
i++;
}
i've tested $nama_desa[0] and $nama_desa[1] and they have value returned (the value is "Kranon" and "Wulung") and i use the value like $Kranon['proyek'] and theres no error and returned the value that i want, but when i combined it with $nama_desa[$i]['proyek'] i got this error.
`
Please help, thanks in advance
You only push $row->nama_desa to $nama_desa. and try to get ['proyek'] from $nama_desa?
As you explained above, you getting value with this $nama_desa[1] but you trying to access this key $nama_desa[$i]['proyek'] which means its looking for $nama_desa[1]['proyek'] which is not exist.
Just do
print_r($name_desa);die;
You will find there is no key present with the name of 'proyek' on $name_desa[1] (key '1' i have only given for example. It can be any number of key)
I guess you will get your value by accessing this $nama_desa['proyek'] OR You will get idea with print result.
I have just found my solution.
I always getting an error whenever i want to pass variable that refers another value into foreach, so I modified my controller so I can pass the value into foreach in View directly. And I moved kind of "get-data-from-API" from Controller into View.
My Controller :
$datakonten['getAllDesa'] = $this->M_desa->getAllDesa($idStatus);
$data['content'] = $this->load>view('public/konten/v_home',$datakonten,TRUE);
My View :
foreach($getAllDesa as $rows)
{
$proyek = json_decode($this->curl->simple_get($rows->alamat_api_lelang));
foreach($proyek as $baris)
{
$namaProyek = $baris->nama_proyek;
?>
Nama Proyek : <?php echo $namaProyek;?></br>
<?php
}
}

How to create logic hook in SuiteCRM Leads to calculate and display Days Since Last Activity for a given record

This would be displayed in a new field Days Since Last Activity and based on Today minus Date Modified.
You can do something like this on whatever hook u want
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class logic_hooks_class
{
function after_retrieve_method($bean, $event, $arguments)
{
$date_modified = $bean->date_modified;
$datetime1 = new DateTime();
$datetime2 = new DateTime($date_modified);
$interval = $datetime1->diff($datetime2);
$elapsed = $interval->format('%a');
$bean->days_since_last_activity_c = $elapsed;
}
}
?>

Resources