Skip to content

Instantly share code, notes, and snippets.

View aklimaruhina's full-sized avatar

Aklima Akther ruhina aklimaruhina

View GitHub Profile
1. create controller
public function search(Request $request)
{
$query = $request->input('query');
$data = DB::table('my_table')
->where('column1', 'LIKE', '%' . $query . '%')
->orWhere('column2', 'LIKE', '%' . $query . '%')
->paginate(10);
@aklimaruhina
aklimaruhina / datatables.js
Created February 18, 2023 05:15 — forked from usmcamp0811/datatables.js
Custome PDF in DataTables Example
$(document).ready(function() {
// Function to convert an img URL to data URL
function getBase64FromImageUrl(url) {
var img = new Image();
img.crossOrigin = "anonymous";
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width =this.width;
canvas.height =this.height;
var ctx = canvas.getContext("2d");
first step : css
.color-0 {
background-color: #F8B195;
}
.color-1 {
background-color: #F67280;
}
.color-2 {
background-color: #C06C84;
}
1. add appends variable
protected $appends = ['bd_amount_in_text'];
2. add function in models
public function getBdAmountInTextAttribute($value)
{
$output_string = '';
$amount = $this->paid_amount; //this is paid amount to translate
$tokens = explode('.', $amount);
$current_amount = $tokens[0];
step1: need to show total price of products
add appends to your Order model
1. add this on top protected $appends = ['total_purchase_price', 'update_url'];
2. add functions
// This is another models
public function orderItems() {
return $this->hasMany('App\OrderItem', 'order_id');
}
1.step one: add following this code to your category model
// Each category may have multiple products
public function products()
{
return $this->belongsToMany(Product::class)->orderBy('id','DESC'); //since its a manytomany relation
}
2. step two: to show them in your view file
first get all category
@foreach($categories as $key => $category)
@foreach($category->products->where('show_home',1)->where('total_qty', '>', 0)->take('11') as $pKey => $product)
when you need to use map function while imploading
function implodeProduct($product){
$multiplied = $product->stocks->map(function ($item, $key) {
return $item->size .' = '.$item->qty ;
});
return $multiplied->implode(', <br>');
}
and model
// each product might have many product
public function stocks()
When you need to find your sell price along with discount price
function getSalePrice($reg_price, $dis_amount, $dis_type) {
if($dis_type){
// if discount amount percentage(%)
$sale_price = (float)$reg_price - ((float)$reg_price * (float)$dis_amount/100);
$sale_price = round($sale_price, 2);
} else{
// if discount amount fixed
$sale_price = (float)$reg_price - (float)$dis_amount;
}