laravel database model "with" function - laravel

I'm new in Laravel please me.
I'm working on laravel project which is already done by other developers.
I am stuck in Model::with function.
QxAppDetail::with(['qx_app_translation', 'qx_app_pages.qx_page_translation',
'user_app_info' => function($query) use($device_registration_id) {
$query->where('device_registration_id', $device_registration_id);
}])->selectRaw($this->table . '.app_id, '
. 'if(qx_app_details.app_icon = "", "", CONCAT("' . $this->app_icon_path . '","/", qx_app_details.app_icon)) as app_icon, '
. 'if(qx_app_details.download_link="","",CONCAT("' . $apk_url . '",qx_app_details.download_link)) as download_link,'
. $this->table . '.open_link, qx_app_details.package_name, qx_app_details.qeexo_default_app, qx_app_details.service_id,qx_app_details.sort_order,qx_app_details.is_enabled')
->orderBy('qx_app_details.sort_order', 'ASC')
->whereIn('qx_app_details.device_registration_id', array(0, $device_registration_id))
->get();
in above query i need to concat url with column like
'if(qx_app_details.download_link="","",CONCAT("' . $apk_url . '",qx_app_details.download_link)) as download_link,'
in qx_app_pages. but i'm not able to do this.
qx_app_pages and qx_page_translation are tables
Current Query output is:
[{"app_id":472,"app_icon":"","download_link":"","open_link":"","package_name":"com.android.settings","qeexo_default_app":"0","service_id":"9","sort_order":"0","is_enabled":"1","qx_app_translation":[{"locale":"en_US","app_name":"Settings","app_description":""}],"qx_app_pages":[{"page_id":213,"page_icon":"iVBORw0KGgoAAAANSUhEUgAAAGYAAABmCAMAAAAOARRQAAAApVBMVEX\/\/\/80d+D09PQ1dNb+\/v79\n\/f319fX29vb8\/Pz5+fk1dNg0d94zduAsc98ncd8hb9\/w9f0tcNV0n+n2+fwpbtWJruyxyvOVtu7E\n1vXs8vzj6\/rc5vk1dta1x+iUr+NXjeU7fuJLhuPR3PeApOqsw\/Bgkua+0fTX4fCUs+xumN\/j6fFr\nl+ectOS\/zuvO1+ykwPARad1XhdhBfNd6oeBbjNqHqeJ1neFQlFnoAAAGlElEQVRogb2afV+bPBSG\neQsBSqCU2td1Fm1r1TnndPv+H+1JApS8nITU\/Xzyx+aRmpucKzl3QvG8\/79Ft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N\/EsfysgsbC9Xr6JD2u\nVq+zWPQXFMPP07D1DSP+CkvkHicYg28lyG9HqW9LjcVoJL6iV\/XzQnzZXRji7q+U98k+Fav9aSrQ\nu3NIeXduNPbMcf\/rL31v8D+2OXl\/9El2FQAAAABJRU5ErkJggg==","action":"com.android.settings","app_id":"472","qeexo_default_page":"0","is_deleted":"0","qx_page_translation":[{"page_name":"Home","locale":"en_US"}]}],"user_app_info":{"order_id":391,"device_registration_id":"11862","app_id":"472","default_page_id":"213","sort_order":"0","qeexo_default_app":"1","is_enabled":"1"}}]
Thanks in advance.

Related

Convert Query from Codeigniter to Laravel 8

How to write this query in laravel? this query was used in Codeigniter
$ci->db->query("SELECT ratings.rating_id," . $table . "." . $namefield . " as thenamefield,ROUND(AVG(ratings.rating_num),2) as rating
FROM ratings," . $table . " WHERE " . $table . "." . $idfield . " = ratings.rating_id GROUP BY rating_id
ORDER BY rating DESC LIMIT " . $limit . "");
try this
$select_part = $table . "." . $namefield;
DB::table('ratings')
->select('ratings.rating_id',DB::raw("{$select_part} as thenamefield"),DB::raw("ROUND(AVG(ratings.rating_num)2) as rating"))
->crossJoin($table)
->whereRaw("{$select_part} = ratings.rating_id")
->groupBy("rating_id")
->orderByRaw("rating DESC")
->limit($limit)
->get();

Excel file with Multiple Sheets in Laravel-Excel 3.1 -> Import Original and Store + Store Individual sheets after cell validations

Thanks for the reaching out to my question, but i have got a problem, I'm trying to Import an excel file with multiple sheets.
Find sheets by some cell-value validation, like if on cell E7, i have a value, store this sheet as separate file. I'm doing mapping() for cell values, and then trying to use Excel::store to save each individual sheet separately. Can't receive any data for individual sheets
Also store the original file. This works!
The issue is, i can't receive any data for storing individual-sheets as excel files, i can create the individual excel files, but no data is being received, or maybe i'm not using the right data-format mentioned on documentation.
Please also check the code. Any help would be appreciated.
public function mapping(): array
{
return [
'altafit_id' => 'E7',
'year' => 'B3',
'initial_month' => 'B4',
'final_month' => 'B5',
];
}
public function model(array $row)
{
// dd($row);
$name = $row['altafit_id'];
$year = $row['year'];
$initial_month = $row['initial_month'];
$final_month = $row['final_month'];
$file_type = 'club';
// dd(collect((object) $row));
Excel::store(collect((object) $row), 'P&L_' . $name . '_' . $year . '_' . $initial_month . '_06' . ',clubs' . ',' . $initial_month . ',' . $final_month . '.' . 'xls', 'public');
return new Files([
//'user_id' => $row['user_id'],
'file_name' => 'P&L_' . $name . '_' . $year . '_' . $initial_month . '_06' . ',clubs' . ',' . $initial_month . ',' . $final_month . '.' . 'xls',
'file_type' => $file_type
]);
}
Already check the documentation, but doesn't work for me.
https://docs.laravel-excel.com/3.1/getting-started/

laravel deserialize/decode job raw body

i'm experiencing one problem here. Sample will speak for it self.
Queue::after(function (JobProcessed $event) {
$job_details = json_decode($event->job->getRawBody(), true);
)});
This is how $job_details looks like:
'displayName' => 'App\\Jobs\\CommandJob',
'job' => 'Illuminate\\Queue\\CallQueuedHandler#call',
'maxTries' => 10,
'timeout' => NULL,
'data' =>
array (
'commandName' => 'App\\Jobs\\CommandJob',
'command' => 'O:19:"App\\Jobs\\CommandJob":9:{s:32:"' . "\0" . 'App\\Jobs\\CommandJob' . "\0" . 'commandName";N;s:30:"' . "\0" . 'App\\Jobs\\CommandJob' . "\0" . 'arguments";N;s:28:"' . "\0" . 'App\\Jobs\\CommandJob' . "\0" . 'command";s:20:"google:get-campaigns";s:5:"tries";i:10;s:32:"' . "\0" . 'App\\Jobs\\CommandJob' . "\0" . 'nextCommand";a:1:{i:0;s:19:"google:get-adgroups";}s:6:"' . "\0" . '*' . "\0" . 'job";N;s:10:"connection";N;s:5:"queue";s:11:"update_data";s:5:"delay";N;}',
I would like to get some params from $job_details['data']['command'].
Is there some simple way to do this , or i need some home made soultion ?
$event->job->getRawBody returns a string so you can't write $job_details['data']['command'] and you will end up with Illegal string offset error.
I am using Laravel 5.4 and i have managed to retrieve my Job instance using $event->job->payload() then applying the unserialize method according to the documentation.
So what i did is :
$payload = $event->job->payload();
$myJob = unserialize($payload['data']['command']);
$myJob->getMyProperty();
//... Just work with $myJob as if it were your job class
The $job_details["data"]["command"] is a string generated from serialize($value). You can unserialize($str) it to create the job object represented by your string. You will then have access to the properties according to the usual visibility rules.
$job = unserialize($job_details["data"]["command"]);
dump($job->queue;) // "update_data"
I was having error with an email that contained some space in it. To fix the problem and send it, I had to decode the payload of the failed jobs and remove the space in the email.
To do so, in php artisan tinker
// take some specific failed jobs
$failed_job = DB::table('failed_jobs')->where('id', $your_job_id)->first();
$payload = json_decode($failed_job->payload);
$obj = unserialize($payload->data->command);
// here I have the user content, I can see the wrong email
$user = $obj->notifiables;
//update email and save
$user->email = "newemail#something"
$user->update()
As the last step, push again the jobs into the queue.

How to filter {ITEM_TITLE} and {ITEM_DESCRIPTION} osclass keywords before using them in emails?

How to filter {ITEM_TITLE} and {ITEM_DESCRIPTION} osclass keywords before using them in emails?
I want to apply a function on the item_title and item_description before using them in emails.
Ex.
Title: Sell bmw_ x5__
To become
Sell bmw x5
without changing the database values
I have the function
removeunderline(argument) that works, I only need to know from where to call it or where to use it.
(Osclass forums are blocked for new users, that's why I ask here)
/oc-includes/osclass/emails.php
Put removeunderline() at {ITEM_TITLE} and {ITEM_DESCRIPTION} values.
Example:
$words = array();
$words[] = array(
'{ITEM_DESCRIPTION_ALL_LANGUAGES}',
'{ITEM_DESCRIPTION}',
'{ITEM_COUNTRY}',
'{ITEM_PRICE}',
'{ITEM_REGION}',
'{ITEM_CITY}',
'{ITEM_ID}',
'{USER_NAME}',
'{USER_EMAIL}',
'{ITEM_TITLE}',
'{ITEM_URL}',
'{ITEM_LINK}',
'{VALIDATION_LINK}',
'{VALIDATION_URL}',
'{EDIT_LINK}',
'{EDIT_URL}',
'{DELETE_LINK}',
'{DELETE_URL}'
);
$words[] = array(
$all,
removeunderline($item['s_description']), // here
$item['s_country'],
osc_format_price($item['i_price']),
$item['s_region'],
$item['s_city'],
$item['pk_i_id'],
$item['s_contact_name'],
$item['s_contact_email'],
removeunderline($item['s_title']), // here
$item_url,
$item_link,
'<a href="' . $validation_url . '" >' . $validation_url . '</a>',
$validation_url,
'' . $edit_url . '',
$edit_url,
'' . $delete_url . '',
$delete_url
);
Do the same for all {ITEM_TITLE} in this file (10 replacements).
Do the same for all {ITEM_DESCRIPTION} in this file (3 replacements).

Get latitude and longitude given name and address

I have a CSV file with name,area,city fieds and I'm expecting that CSV with following fields name,area,city,latitude,longitude
Can any one suggest which API is best for these,
I already tried
Google API's
Textsearch: this is giving overall city wise. Not particular
eg: kfc, in jp nagar 1st phase, bangalore it throws all over bangalore kfc list
I want exactly
echo $url = "https://maps.googleapis.com/maps/api/geocode/json?address=" . $name1 . "+" . $area1 . "+" . $city . "&key=" . $api_key;
Which API will fulfill my requirement?
I tried this also
$url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=". $name1 . "+" . $area1 . "+" . $city . "&key=" . $api_key;

Resources