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();
Related
I'm trying to upload an image file to the database. But, when it posted, it shows a full path of the image file (I use the getClientOriginalName() to get the filename).
DSController.php
public function createDS2(Request $request)
{
//dd($request->all());
$imgName1 = $request->file('opsi_a')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_a')->extension();
$imgName2 = $request->file('opsi_b')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_b')->extension();
$imgName3 = $request->file('opsi_c')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_c')->extension();
$imgName4 = $request->file('opsi_d')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_d')->extension();
$data = new DS2;
$data->pertanyaan = $request->input('pertanyaan');
$data->opsi_a = $request->file('opsi_a')->move(public_path('image'), $imgName1);
$data->opsi_d = $request->file('opsi_b')->move(public_path('image'), $imgName2);
$data->opsi_b = $request->file('opsi_c')->move(public_path('image'), $imgName3);
$data->opsi_c = $request->file('opsi_d')->move(public_path('image'), $imgName4);
$data->kunci = $request->input('kunci');
$data->save();
return redirect('ds2');
}
the image file in the database will show something like this :
C:\xampp\htdocs\admin_kuis\public\image\hiu_press.png-1614165665.png
how I can just save the hiu_press.png-1614165665.png in my database?
The same way as #zia-yamin but different syntax.
$imgName1 = $request->file('opsi_a')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_a')->extension();
$imgName2 = $request->file('opsi_b')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_b')->extension();
$imgName3 = $request->file('opsi_c')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_c')->extension();
$imgName4 = $request->file('opsi_d')->getClientOriginalName() . '-' . time() . '.' . $request->file('opsi_d')->extension();
$request->file('opsi_a')->move(public_path('image'), $imgName1);
$request->file('opsi_b')->move(public_path('image'), $imgName2);
$request->file('opsi_c')->move(public_path('image'), $imgName3);
$request->file('opsi_d')->move(public_path('image'), $imgName4);
$data = new DS2;
$data->pertanyaan = $request->input('pertanyaan');
$data->opsi_a = pathinfo($imgName1, PATHINFO_BASENAME);
$data->opsi_b = pathinfo($imgName2, PATHINFO_BASENAME);
$data->opsi_c = pathinfo($imgName3, PATHINFO_BASENAME);
$data->opsi_d = pathinfo($imgName4, PATHINFO_BASENAME);
$data->kunci = $request->input('kunci');
$data->save();
return redirect('ds2');
Use This Code:
if ($request->hasFile('file_name')) {
$file_name = $request->file('file_name');
$file_name = time() . $file_name->getClientOriginalName();
}
store your file full path in $stored_file variable and then use this one:
$data->opsi_d = $request->file('opsi_b')->move(public_path('image'), pathinfo($imgName2)['basename']);
Also, you can use:
$file = Input::file('image');
$fileName = $file->move(public_path('image'), $imgName1->getOriginalFileName());
$fileName->image = $fileName ->getRealPath();
Since around March of this year our osTicket system started posting duplicate tickets and duplicate threads.
I've tried everything method I know of to troubleshoot and identity where and why this is occurring. I've even implemented a catch condition to check the db tables prior to inserting tickets and threads to see if the contents of the $vars[]'s match what is already in the DB tables.
No success to solve this problem whatsoever.
I've Googled it and see where this issue has been in existence and dates back a number of years.
Does any one have a solution on how to stop osTicket from consistently creating ducpliate tickets and threads?
I tried the following from piecing together suggestions others have made out there in the various osTicket up through v1.10. Here is the code I tried. It actually worked for 2-days straight, then began to fail again yesterday.
Inserted around line 2498 in ./include/class.ticket.php right before if($errors) return 0;.
/**
* J.Doe added to intercept duplicate ticket entries.
* Updated: 2017-06-12
* #author John Doe <jd#example.com>
*/
$sql1='
SELECT ticketID FROM ost_ticket
WHERE
source = "' . $vars['source'] . '"
AND topic_id = "' . $vars['topicId'] . '"
AND url = "' . $vars['url'] . '"
AND priority_id = "' . $vars['priorityId'] . '"
AND duedate = "' . date( 'Y-m-d H:i:s', strtotime( $vars['duedate'] . ' ' . $vars['time'] ) ) . '"
AND team_id = "' . $vars['assignId'] . '"
AND subject = "' . $vars['subject'] . '"
AND dept_id = "' . $vars['deptId'] . '"
AND email = "' . $vars['email'] . '"
AND name = "' . $vars['name'] . '"
';
$sql2='
SELECT id FROM ost_ticket_thread
WHERE
staff_id = "' . $vars['assignId'] . '"
AND poster = "' . $vars['name'] . '"
AND title = "' . $vars['subject'] . '"
AND body = "' . $vars['message'] . '"
';
$res1=db_query($sql1);
$res2=db_query($sql2);
if( ( $res1 && db_num_rows( $res1 ) ) || ( $res2 && db_num_rows( $res2 ) ) ) {
header( 'Location: http://example.com/workorders/' );
exit;
}
//Any error above is fatal.
if($errors) return 0;
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\/79FtH1l3DaUJAlS4ujz\ncaReh1WST8SRJe5+m6ZposTIHEdqnAIxpIIlldQeRyxGthhLcd8Lxji5MkbmOFKvd5+K4zhxitdr\n03WxV6zEbUtwHKTiXwVBIGUoCLpeo+WB\/oMvcftLFiNz7LWMKJfYoiLG0+Y49VJAxRYjLoMYLjcV\nb1WQlXodK2NXx9bOa5TIM9mm4h1J\/pboKsgSp1yGitlUIilD219+Nt+lV3ChMz1J2jE5j8W7J1lY\nfUyVXm1c2KKPuIw0QqvK3b4Kw2yyGK5jnZM8NtzVgshdpb6hKuGEPK9FFRuXOMZAxbFyodMsZGPx\n\/eK1v9fR9ROPq6hx\/VhxFT9vNkYVIUY0hiqOXcXbzWnGfNaKGxaPZEyrBW4q8besU6E6W5C+zIXG\nV3Px0j9V1qv45LmGKs6\/jyX9+XtQ8fPJIf4KLunTezWo+H718YA\/wSUeUYl3kgqtBd8\/wYX6jYUL\nXcsPv3NJJczInfHeIzVjg9\/YxoKD9C9RVCbkKKlYuHR+Q1XwiMqLOJYw5OunWFyuW7k4+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rmw\/4slmDFk8BvqBLeKEwD3rsX5\/gSqmPyGVvL7wQrcuPg9GpWL5XyD\nvNPlCYojF4bmHuCC+i9tI+kb3X6V9v45MpPF3bq\/AjKG+y9lAb+hbVFexYUN5gioWP2GtpoPx5kL\nbeVK42Lxm57ToryuRhczFOkqAfBsUHpOOWXf1rlyYQa99ZSMJWYnEObcHS1srlzoae3ExyJxGfMb\nHqeHKlR7NdbsYlljPWMjfsPjOHgv5F7NGSxnbiras3H2qXomP7M1cumeQY1zYX6jn7XWszx34XKe\nOqroz9N4zV7fFxCXiXSGnizGMmbwm4FTfVPmVi55eXsXKSqw30SK38jnk1OjrZ8Ll5zkzaFW14ub\n36h7+s2f33OVS\/v9TeEfl2vt3lUuZr+RZkMavPzZF9I3K8z3STm5P210Dlo8+A3kBEIGcb15bX6V\nBclpq7JqXpS\/JrPFpgY4aDGG\/Mb8pHd6Wj7fNs3b29vH\/fK06XsZ4ZLEsN\/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.
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;
In the new version of Googles PHP-API-Cient the Google_Signer_P12 class was removed and now you should create signed urls via Firebase JWT (see https://github.com/google/google-api-php-client/blob/master/UPGRADING.md).
Unfortunately this doesn't work for me (I am trying to generate signed urls for cloud storage downloads). My previous (working) code looked like this:
$signer = new \Google_Signer_P12( 'privatekey.p12' , 'notasecret' );
$stringToSign = 'GET' . "\n" . "\n" . "\n" . $expires . "\n". '/' . $bucketName . '/' . $fileName;
$signature = $signer->sign( utf8_encode( $stringToSign ) );
$finalSignature = \Google_Utils::urlSafeB64Encode( $signature );
I tried to replace this with:
$stringToSign = 'GET' . "\n" . "\n" . "\n" . $expires . "\n". '/' . $bucketName . '/' . $fileName;
$finalSignature = \JWT::encode(
$stringToSign,
'privateKey.p12'
);
but I receive a "SignatureDoesNotMatch" error. Unfortunately I couldn't find anything in the docs on how to upgrade this part of the code.