This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first step : css | |
.color-0 { | |
background-color: #F8B195; | |
} | |
.color-1 { | |
background-color: #F67280; | |
} | |
.color-2 { | |
background-color: #C06C84; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When you need to add active link to your admin panel dashboard and make them show their activity status. following this code will hhelp. | |
#laravel #admin-panel | |
<li class="nav-main-item"> | |
<a class="nav-main-link{{ request()->is('admin') ? ' active' : '' }}" href="/admin"> | |
<i class="nav-main-link-icon si si-cursor"></i> | |
<span class="nav-main-link-name">Dashboard</span> | |
</a> | |
</li> | |
<li class="nav-main-item{{ request()->is('admin/orders/*') || request()->is('admin/orders') || request()->is('admin/orders-record/*') ? ' open' : '' }}"> | |
<a class="nav-main-link nav-main-link-submenu" data-toggle="submenu" aria-haspopup="true" aria-expanded="true" href="#"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |