web.php :
Route::get('get-sub-cat-list', 'Admin\BlogPostController@getSubCategoryList')->name('get-sub-cat-list');
controller :
public function getSubCategoryList(Request $request){
$subCatList= SubCategory::where("category_id",$request->category_id)->orderBy('name','ASC')->pluck('id','name');
return response()->json($subCatList);
}
public function store(Request $request)
{
$post->category_id = $request->category;
$post->sub_cat_id = $request->sub_category_id;
}
Model:
public static function selectSubCategoryList($value) {
$result = DB::table('blog_sub_categories')->select('*')->where('category_id', $value)->get();
return $result;
}
public function edit($id)
{
$subcategories= BlogPost::selectSubCategoryList($post->category_id);
}
public function update(Request $request, $id)
{
$post->category_id = $request->category;
$post->sub_cat_id = $request->sub_category_id;
}
create.balte.php:
<div class="row col-md-12">
<div class="col-md-6">
<div class="form-group">
<label class="d-block font-weight-semibold">Post Category<i class="text-danger">*</i></label>
<select id="category_id" name="category" data-placeholder="Select Category" class="form-control form-control-select2" data-fouc>
<option disabled="" selected value>Select Category</option>
@foreach($categories as $category)
<option value="{{$category->id}}" {{ old('category') == $category->id ? 'selected' : '' }}>
{{$category->name}}
</option>
@endforeach
</select>
<span class="text-danger"> {{ $errors->first('name') }}</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="d-block font-weight-semibold">Sub Category<i class="text-danger"></i></label>
<select name="sub_category_id" id="sub_category_id" class="form-control form-control-select2" data-fouc>
<option value>--Select Sub Category--</option>
</select>
<span class="text-danger"> {{ $errors->first('name') }}</span>
</div>
</div>
</div>
<script type="text/javascript">
$('#category_id').change(function(){
var catID = $(this).val();
if(catID){
$.ajax({
type:"GET",
url:"{{route('get-sub-cat-list')}}?category_id="+catID,
success:function(res){
if(res){
$("#sub_category_id").empty();
$("#sub_category_id").append('<option value="">Select Sub Category</option>');
$.each(res,function(key,value){
console.log(value);
$("#sub_category_id").append('<option value="'+value+'">'+key+'</option>');
});
}else{
$("#sub_category_id").empty();
}
}
});
}else{
$("#sub_category_id").empty();
}
});
</script>
Or
<script type="text/javascript">
$('#district').on('change', function(){
var dist_id = $('#district option:selected').val();
if (dist_id==1) {
$('#areaDiv').removeClass('d-none');
var urll="{{ url('/get_area') }}/"+dist_id;
$.ajax({
url:urll,
success: function(data){
if (data !='') {
$("#area").html(data);
}
},
error: function (data) {
}
});
}else{
$('#areaDiv').addClass('d-none');
var area = $('#area');
area[0].selectedIndex = -1;
}
});
</script>
edit.blade.php
<div class="row col-md-12">
<div class="col-md-6">
<div class="form-group">
<label class="d-block font-weight-semibold">Post Category<i class="text-danger">*</i></label>
<select id="category_id" name="category" data-placeholder="Select Category" class="form-control form-control-select2" data-fouc>
<option disabled="" selected value>Select Category</option>
@foreach($categories as $category)
<option value="{{$category->id}}" @if($category->id == $post->category_id) {{ 'selected' }} @endif>
{{$category->name}}
</option>
@endforeach
</select>
<span class="text-danger"> {{ $errors->first('category') }}</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="d-block font-weight-semibold">Sub Category<i class="text-danger"></i></label>
<select name="sub_category_id" id="sub_category_id" class="form-control form-control-select2" data-fouc>
<option value>--Select Sub Category--</option>
@if ($subcategories)
@foreach ($subcategories as $val)
?>
<option value=" {{ $val->id }}" @if ($val->id == $post->sub_cat_id) {{'selected'}}
@endif>{{ $val->name }}
</option>
@endforeach
@endif
</select>
<span class="text-danger"> {{ $errors->first('name') }}</span>
</div>
</div>
</div>
Sunday, July 5, 2020
Add more & Remove in Laravel ?
blade.php :
<div class="row" style="margin-top: 36px">
<div class="col-lg-12">
<div class="box-body no-padding">
<div class="table-responsive">
<table align='center' class="table table-responsive" spacing='2' cellpadding='5' style="width: 700px;">
<thead>
<tr style="background: lightgrey">
<th>Product Name</th>
<th>Action</th>
</tr>
</thead>
<tbody id="productAppendDiv">
<tr class="row_element">
<td style="width:700px;">
<input type="text" name="product_name[]" class="form-control multiple_product" placeholder="Type product name"/>
</td>
<td>
<button type="button" class="btn btn-danger deleteProductRow " style="width: 40px; height: 40px"><i class="fa fa-trash"> </i></button>
</td>
</tr>
</tbody>
</table>
<div class="col-md-8">
<button type="button" class="btn btn-success btn-sm add pull-right" id="addMoreProducts"><span class="fa fa-plus"></span> Add More Product</button>
</div>
</div>
</div>
</div>
</div>
<table id="productHideDiv" style="display: none">
<tr class="row_element">
<td style="width: 700px;">
<input type="text" name="product_name[]" class="form-control multiple_product" placeholder="Type product name"/>
</td>
<td>
<button type="button" class="btn btn-danger deleteProductRow " style="width: 40px; height: 40px"><i class="fa fa-trash"> </i></button>
</td>
</tr>
</table>
<script type="text/javascript">
$( document ).ready(function() {
$('#addMoreProducts').click(function(){
var cloned=$('#productHideDiv tr').first().clone(true);
cloned.appendTo('#productAppendDiv');
});
});
$(document).on("click", ".deleteProductRow", function () {
$(this).parents('.row_element').remove();
});
</script>
controller :
public function store(Request $request)
{
$post = new BlogPost;
$post->save();
$productDetails = $this->makeProductDataFormat($request->product_name,$post->id);
if(count($productDetails) > 0) {
BlogProduct::insert($productDetails);
}
}
public function makeProductDataFormat($data,$postId) {
BlogProduct::where('post_id',$postId)->delete(); //use update function
$productDetailsData = [];
if(isset($data)){
foreach ($data as $value) {
$product = Product::where(['status'=>1, 'name'=>$value])->first();
if($product){
$productDetailsData[] =[
'post_id' => $postId,
'product_id' => $product->id,
];
}
}
}
return $productDetailsData;
}
<div class="row" style="margin-top: 36px">
<div class="col-lg-12">
<div class="box-body no-padding">
<div class="table-responsive">
<table align='center' class="table table-responsive" spacing='2' cellpadding='5' style="width: 700px;">
<thead>
<tr style="background: lightgrey">
<th>Product Name</th>
<th>Action</th>
</tr>
</thead>
<tbody id="productAppendDiv">
<tr class="row_element">
<td style="width:700px;">
<input type="text" name="product_name[]" class="form-control multiple_product" placeholder="Type product name"/>
</td>
<td>
<button type="button" class="btn btn-danger deleteProductRow " style="width: 40px; height: 40px"><i class="fa fa-trash"> </i></button>
</td>
</tr>
</tbody>
</table>
<div class="col-md-8">
<button type="button" class="btn btn-success btn-sm add pull-right" id="addMoreProducts"><span class="fa fa-plus"></span> Add More Product</button>
</div>
</div>
</div>
</div>
</div>
<table id="productHideDiv" style="display: none">
<tr class="row_element">
<td style="width: 700px;">
<input type="text" name="product_name[]" class="form-control multiple_product" placeholder="Type product name"/>
</td>
<td>
<button type="button" class="btn btn-danger deleteProductRow " style="width: 40px; height: 40px"><i class="fa fa-trash"> </i></button>
</td>
</tr>
</table>
<script type="text/javascript">
$( document ).ready(function() {
$('#addMoreProducts').click(function(){
var cloned=$('#productHideDiv tr').first().clone(true);
cloned.appendTo('#productAppendDiv');
});
});
$(document).on("click", ".deleteProductRow", function () {
$(this).parents('.row_element').remove();
});
</script>
controller :
public function store(Request $request)
{
$post = new BlogPost;
$post->save();
$productDetails = $this->makeProductDataFormat($request->product_name,$post->id);
if(count($productDetails) > 0) {
BlogProduct::insert($productDetails);
}
}
public function makeProductDataFormat($data,$postId) {
BlogProduct::where('post_id',$postId)->delete(); //use update function
$productDetailsData = [];
if(isset($data)){
foreach ($data as $value) {
$product = Product::where(['status'=>1, 'name'=>$value])->first();
if($product){
$productDetailsData[] =[
'post_id' => $postId,
'product_id' => $product->id,
];
}
}
}
return $productDetailsData;
}
update confirm button from table list using sweet Alert & Ajax Post method ?
JS :
<script src="{{ asset('backoffice/global_assets/bootstrap-sweetalert/dist/sweetalert.min.js') }}"></script>
CSS :
<link rel="stylesheet" href="{{ asset('backoffice/global_assets/bootstrap-sweetalert/dist/sweetalert.css') }}">
wep.php:
Route::post(
'delivery-man/deposit_status',
'Admin\DeliveryManMoneyController@depositStatusChange'
)->name('delivery-man.deposit_status');
controller :
public function depositStatusChange(Request $request){
$deposit=DeliveryManCollection::where(
'id', $request->collection_id
)->first();
$deposit->deposit_status=1;
$deposit->update();
return ['msg'=>'Money deposited.'];
}
blade.php :
<td>
@if($row->deposit_status ==1)
<button class="btn btn-danger" >Deposited</button>
@else
<button class="btn btn-danger btn-xs action-button deposit_status_change" data-id=" {{$row->id}}">Deposit
</button>
@endif
</td>
<script type="text/javascript">
$(function(){
$('.deposit_status_change').click(function() {
var collection_id=$(this).data('id');
//console.log(urll)
swal({
title: "Are you sure?",
text: "Press Yes to confirm or press No to cancel.",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: true,
closeOnCancel: true
},
function(isConfirm){
if(isConfirm){
$.ajax({
url: "{{ route('delivery-man.deposit_status') }}",
type: 'POST',
data: {
collection_id: collection_id,
_token: "{{ csrf_token() }}"
},
success: function(res){
$.jGrowl(res.msg, {
header: 'Success',
theme: 'alert-bordered alert-styled-left alert-success'
});
location.reload();
},
error: function (data) {
$.jGrowl('Sorry form submission failed. Try again later.', {
header: 'Error',
theme: 'alert-bordered alert-styled-left alert-danger'
});
}
});
}
});
});
});
</script>
<script src="{{ asset('backoffice/global_assets/bootstrap-sweetalert/dist/sweetalert.min.js') }}"></script>
CSS :
<link rel="stylesheet" href="{{ asset('backoffice/global_assets/bootstrap-sweetalert/dist/sweetalert.css') }}">
wep.php:
Route::post(
'delivery-man/deposit_status',
'Admin\DeliveryManMoneyController@depositStatusChange'
)->name('delivery-man.deposit_status');
controller :
public function depositStatusChange(Request $request){
$deposit=DeliveryManCollection::where(
'id', $request->collection_id
)->first();
$deposit->deposit_status=1;
$deposit->update();
return ['msg'=>'Money deposited.'];
}
blade.php :
<td>
@if($row->deposit_status ==1)
<button class="btn btn-danger" >Deposited</button>
@else
<button class="btn btn-danger btn-xs action-button deposit_status_change" data-id=" {{$row->id}}">Deposit
</button>
@endif
</td>
<script type="text/javascript">
$(function(){
$('.deposit_status_change').click(function() {
var collection_id=$(this).data('id');
//console.log(urll)
swal({
title: "Are you sure?",
text: "Press Yes to confirm or press No to cancel.",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: true,
closeOnCancel: true
},
function(isConfirm){
if(isConfirm){
$.ajax({
url: "{{ route('delivery-man.deposit_status') }}",
type: 'POST',
data: {
collection_id: collection_id,
_token: "{{ csrf_token() }}"
},
success: function(res){
$.jGrowl(res.msg, {
header: 'Success',
theme: 'alert-bordered alert-styled-left alert-success'
});
location.reload();
},
error: function (data) {
$.jGrowl('Sorry form submission failed. Try again later.', {
header: 'Error',
theme: 'alert-bordered alert-styled-left alert-danger'
});
}
});
}
});
});
});
</script>
Monday, January 6, 2020
Display image and href from database in Vue js & Javascript datatable
# You can do it :
Vue Js :
passport_nid: {
label: 'NID',
render: (data,type,row) => { return '<img src=" '+ base_url+' '+"uploads/"+' '+"nid_image_folder/" + ' '+row.passport_nid+' " alt="" class="imageSize" width="70px">'}
},
JavaScript :
Ex:01 .html('<img src="'+{{URL::asset('uploads/studentPhoto/')}}+' '+value.photo+'" width="200px;" height="200px">')
Ex:02
var url ='{{url("/privilege")}}';
$("#my_country").html('<a href="'+url+'" title="Become a VIP">VIP Privileges</a>');
Wednesday, January 1, 2020
Laravel Module (nwidart/laravel-modules) package Artisan command
Step:01
#To install through Composer, by run the following command:
Step:02
#By default the module classes are not loaded automatically. You can autoload your modules using psr-4. For example :
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
}
}
Step:03
#Tip: don't forget to run composer dump-autoload afterwards
Step:04
Module Artisan Command:
#To install through Composer, by run the following command:
- composer require nwidart/laravel-modules
- php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
Step:02
#By default the module classes are not loaded automatically. You can autoload your modules using psr-4. For example :
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
}
}
Step:03
#Tip: don't forget to run composer dump-autoload afterwards
Step:04
Module Artisan Command:
- php artisan module:make Blog
- php artisan module:make-migration create_posts_table Blog
- php artisan module:migrate Blog
- php artisan module:seed Blog
- php artisan module:make-controller PostsController Blog
- php artisan module:make-model Post Blog
- php artisan module:make-provider BlogServiceProvider Blog
- php artisan module:make-request CreatePostRequest Blog
Thursday, November 14, 2019
How to create migration load into subfolder ?
Note : If create table in migration sub folder
Create Table
php artisan make:migration create_sample_table --path=database/migrations/sub_folder
Note : If multiple Sub Folder migration
# php artisan migrate --path=database/migrations/sub_folder1
# php artisan migrate --path=database/migrations/sub_folder2
Note: If single subfolder migration:
# php artisan migrate --path=/database/migrations/*
Create Table
php artisan make:migration create_sample_table --path=database/migrations/sub_folder
Note : If multiple Sub Folder migration
# php artisan migrate --path=database/migrations/sub_folder1
# php artisan migrate --path=database/migrations/sub_folder2
Note: If single subfolder migration:
# php artisan migrate --path=/database/migrations/*
How to create laravel Custom helper ?
First Example :
Step#01
Create a HrHelper.php file in your app/Helpers folder and load it up with composer.json:
"autoload": {
"classmap": [
...
],
"psr-4": {
"App\\": "app/"
},
"files": [
"app/Helpers/HrHelper.php" // <---- ADD THIS
]
},
Step#02
After adding that to your composer.json file, run the following command:
composer dump-autoload
Step#03
#Apply your function in SampleControlle
<?php
namespace App\Http\Controllers\HR\Employee;
public function index(Request $request){
$headPersonList =getHeadPersonList();
return view('employee',compact('headPersonList'));
}
Second Example :
Step#01
Create your helper Helpers/HrHelper.php
namespace App\Helpers;
use App\Model\HR\HrManageEmployee;
class HrHelper
{
public static function getHeadPersonList(){
$details = HrManageEmployee::where('status',0)
->select('id','user_name')
->get();
foreach ($details as $row) {
$headPersonListData[] = [
'id' => $row->id,
'user_name' => $row->user_name,
];
}
return $headPersonListData;
}
}
Step#02
Create an alias :
aliases' => [
...
'Helper' => App\Helpers\HrHelper::class,
]
Step#03
composer dump-autoload
Step#04
#Apply your function in SampleControlle
<?php
namespace App\Http\Controllers\HR\Employee;
use App\Helpers\HrHelper;
public function index(Request $request){
$headPersonList =HrHelper::getHeadPersonList();
return view('employee',compact('headPersonList'));
}
Step#01
Create a HrHelper.php file in your app/Helpers folder and load it up with composer.json:
"autoload": {
"classmap": [
...
],
"psr-4": {
"App\\": "app/"
},
"files": [
"app/Helpers/HrHelper.php" // <---- ADD THIS
]
},
Step#02
After adding that to your composer.json file, run the following command:
composer dump-autoload
Step#03
#Apply your function in SampleControlle
<?php
namespace App\Http\Controllers\HR\Employee;
public function index(Request $request){
$headPersonList =getHeadPersonList();
return view('employee',compact('headPersonList'));
}
Second Example :
Step#01
Create your helper Helpers/HrHelper.php
namespace App\Helpers;
use App\Model\HR\HrManageEmployee;
class HrHelper
{
public static function getHeadPersonList(){
$details = HrManageEmployee::where('status',0)
->select('id','user_name')
->get();
foreach ($details as $row) {
$headPersonListData[] = [
'id' => $row->id,
'user_name' => $row->user_name,
];
}
return $headPersonListData;
}
}
Step#02
Create an alias :
aliases' => [
...
'Helper' => App\Helpers\HrHelper::class,
]
Step#03
composer dump-autoload
Step#04
#Apply your function in SampleControlle
<?php
namespace App\Http\Controllers\HR\Employee;
use App\Helpers\HrHelper;
public function index(Request $request){
$headPersonList =HrHelper::getHeadPersonList();
return view('employee',compact('headPersonList'));
}
Subscribe to:
Posts (Atom)
Ajax load lage with laravel.
step-1: HTML <div class="row"> <div class="col-lg-12"> <d...
-
<div id="employeement_more"> <div class="row employeementAppendDiv" style="border-top: 1px dotted #d...
-
Step:01 #To install through Composer, by run the following command: composer require nwidart/laravel-modules php artisan vendor:publish...
-
Vue JS - Bootstrap Datepicker HTML <div class="m-form__group m-form__group"> <label class="m-label m-label-...