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/*
Thursday, November 14, 2019
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'));
}
Thursday, October 24, 2019
Image Upload with javascript validation in Laravel
Step#01
Create
blade page in View
image_upload.blade.php
<form class="form-horizontal" method="post" action="{{ route('add-job-application') }}" enctype="multipart/form-data">
@csrf
@csrf
<div class="col-md-6 mb-3">
<label for="validationTooltip04">Photo</label>
<input type="file" name="photo" class="form-control photo" id="photo" onchange='image(this)'>
<div class="panel-body center-block" style="margin-top: 5px;">
<img id="showPhoto" src="" style="height:200px;width:200px;border-width:0px;">
</div>
</div>
<label for="validationTooltip04">Photo</label>
<input type="file" name="photo" class="form-control photo" id="photo" onchange='image(this)'>
<div class="panel-body center-block" style="margin-top: 5px;">
<img id="showPhoto" src="" style="height:200px;width:200px;border-width:0px;">
</div>
</div>
</form >
Modal for alert
<div class="modal fade" id="error_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document" style="width: 30%;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel" style="color: red;">Warning</h4>
</div>
<div id="warning_message" class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-danger" data-dismiss="modal" style="color:white;">
Cancel
</button>
</div>
</div>
</div>
</div>
aria-hidden="true">
<div class="modal-dialog" role="document" style="width: 30%;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel" style="color: red;">Warning</h4>
</div>
<div id="warning_message" class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-danger" data-dismiss="modal" style="color:white;">
Cancel
</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
/*----------------Start photo show ---------------------------*/
function image(input) {
var fup = document.getElementById('photo');
var fileName = fup.value;
var extension = fileName.substring(fileName.lastIndexOf('.') + 1);
if (extension === 'jpg' || extension === 'jpeg' || extension === 'png' || extension === 'gif') {
var file_size = '';
var photo = $('.photo ').val();
if (photo) {
var file_size = $('.photo')[0].files[0].size;
}
if (file_size > 80000) {
$('.photo').val('');
$('#showPhoto').attr('src', '');
$('#warning_message').text("The photo may not be greater than 80KB");
$('#error_modal').modal(300, 'show');
return false;
}
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#showPhoto').attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
} else {
$('.photo').val('');
$('#showPhoto').attr('src', '');
$('#warning_message').text("Only JPEG, JPG, PNG or GIF type images are allowed");
$('#error_modal').modal(300, 'show');
return false;
}
}
/*----------------End photo show ---------------------------*/
</script>
/*----------------Start photo show ---------------------------*/
function image(input) {
var fup = document.getElementById('photo');
var fileName = fup.value;
var extension = fileName.substring(fileName.lastIndexOf('.') + 1);
if (extension === 'jpg' || extension === 'jpeg' || extension === 'png' || extension === 'gif') {
var file_size = '';
var photo = $('.photo ').val();
if (photo) {
var file_size = $('.photo')[0].files[0].size;
}
if (file_size > 80000) {
$('.photo').val('');
$('#showPhoto').attr('src', '');
$('#warning_message').text("The photo may not be greater than 80KB");
$('#error_modal').modal(300, 'show');
return false;
}
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#showPhoto').attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
} else {
$('.photo').val('');
$('#showPhoto').attr('src', '');
$('#warning_message').text("Only JPEG, JPG, PNG or GIF type images are allowed");
$('#error_modal').modal(300, 'show');
return false;
}
}
/*----------------End photo show ---------------------------*/
</script>
Step#02
Route::post('add-job-application', 'HomeController@addJobApplication')->name('add-job-application');
public
function addJobApplication(Request
$request){
$input = $request->all();
$image
= $request->file('photo');
if($image){
$imgName=md5(str_random(30).time().'_'.$request->file('photo')).'.'.$request->file('photo')->getClientOriginalExtension();
Image::make($request->file('photo'))->resize(600, 600)->save(public_path('frontEnd/uploads/applicationPhoto/') . $imgName);
$input['photo']=$imgName;
}
if($image){
$imgName=md5(str_random(30).time().'_'.$request->file('photo')).'.'.$request->file('photo')->getClientOriginalExtension();
Image::make($request->file('photo'))->resize(600, 600)->save(public_path('frontEnd/uploads/applicationPhoto/') . $imgName);
$input['photo']=$imgName;
}
JobApplication::create($input);
Monday, September 30, 2019
JavaScript Data Table Search.
Step#01:
<template>
<div class="row">
<div class="item-show-limit col-md-8"><span>Show</span>
<select name="per_page" class="per_page" @change="changePerPage" v-model="perPage">
<option value="10">10</option>
<option value="20">20</option><option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
</select>
<span>Entries</span>
</div> <div class="col-md-4">
<div class="m-input-icon m-input-icon--left">
<input type="text" class="form-control m-input" placeholder="Search..." id="inputSearch"><span class="m-input-icon__icon m-input-icon__icon--left"><span><i class="la la-search"></i></span> </span>
</div>
</div>
</div>
</template>
Step#02:
methods: {
changePerPage(){
var vm = this;
vm.index(1,vm.perPage);
},
var vm = this;
vm.index(1,vm.perPage);
},
datatables(){
$(document).ready(function () {
$("#inputSearch").on("keyup", function () {
var value = $(this).val().toLowerCase();
$("#dataTable tr").filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
},
$(document).ready(function () {
$("#inputSearch").on("keyup", function () {
var value = $(this).val().toLowerCase();
$("#dataTable tr").filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
},
}
created(){
_this.datatables();
}
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-1: HTML <div class="row"> <div class="col-lg-12"> <d...
-
Delete btn: <a href="{!!route('news-letter-delete',$row->id )!!}" class="btn btn-danger deleteBtn pull-right p...