Skip to content

Instantly share code, notes, and snippets.

View rakibdevs's full-sized avatar
🎯
Focusing

Md. Rakibul Islam rakibdevs

🎯
Focusing
View GitHub Profile
@rakibdevs
rakibdevs / multiupdate.php
Created February 1, 2021 12:15
Build query for multiple row update with a single query
public function buildUpdateQuery($table, $update)
{
$qr = "update ".$table." set ";
$cases = [];
$ids = [];
foreach ($update as $key => $val) {
$ids[] = $val['id'];
foreach ($val['data'] as $k => $v) {
$cases[$k][] = "when ".$val['id']." then '".$v."'";
}
@rakibdevs
rakibdevs / TemparatureConvert.php
Created January 9, 2021 04:24
Temperature conversions are performed by using a formula, which differs depending on the two temperature scales you are converting between. For example, to convert 50 degrees Celsius (centigrade) to Fahrenheit, we plug our numbers into the formula as shown below: F = C * 9/5 + 32 F = 50 * 9/5 + 32 F = 90 + 32 F = 122 50 degrees Celsius is equal …
<?php
class TemparatureConvert
{
private function kelToCel($num)
{
return round($num - 273.15, 2);
}
private function celToFar($num)
{
@rakibdevs
rakibdevs / Roaster & Leave
Created November 2, 2020 11:18
Check duplicate entry sql in holiday roaster and leave table
SELECT * FROM holiday_roaster where as_id in (select leave_ass_id from hr_leave where leave_from <= '2020-10-30' and leave_to >= '2020-10-30') and date = '2020-10-30'
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\Post;
class PostController extends Controller
{
@rakibdevs
rakibdevs / slug.php
Last active June 7, 2020 10:54
Laravel unique slug generator in Model Class. Add this function in your model class.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
//...................................
@rakibdevs
rakibdevs / summernote.php
Last active June 1, 2020 19:33
Summernote post or update a content with image in Laravel controller . Supports any utf content. Note:
public function domPost($content)
{
libxml_use_internal_errors(true);
$dom = new \DomDocument();
$dom->loadHtml('<?xml encoding="utf-8" ?>'.$content); // must include this to avoid font problem
$images = $dom->getElementsByTagName('img');
if(count($images)>0)
{
foreach($images as $k => $img)
{
@rakibdevs
rakibdevs / Post.php
Created May 23, 2020 10:08
Laravel next and previous post
class Post extends Model
{
…………………………………….
public function next()
{
return $this->where(‘id’, ‘>’, $this->id)->orderBy(‘id’,’asc’)->first();
}
public function previous()
{
return $this->where(‘id’, ‘<’, $this->id)->orderBy(‘id’,’desc’)->first();