|
<?php |
|
public $timestamps = false; // if dont want to timetamps |
|
protected $table = 'temp_interviewees'; |
|
protected $fillable = ['greetings','']; |
|
protected $hidden = [ ]; |
|
|
|
Bootstrap - buttons typs - https://getbootstrap.com/docs/4.0/components/buttons/ |
|
--------------------------- Commit transaction --------------------------------- |
|
try{ |
|
DB::beginTransaction(); |
|
..... |
|
process your data |
|
..... |
|
DB::commit(); |
|
} catch (\Exception $e) { |
|
DB::rollback(); |
|
return $this->sendError('Something went wrong.', [], 422); |
|
} |
|
|
|
---->Gmail SMTP |
|
-> Go to google |
|
-> 2 step on |
|
-> go to 2Step module |
|
-> find app password |
|
|
|
update env file |
|
MAIL_MAILER=smtp |
|
MAIL_HOST=smtp.gmail.com |
|
MAIL_PORT=465 |
|
[email protected] |
|
MAIL_PASSWORD=342343432c234234 |
|
MAIL_ENCRYPTION=tls |
|
[email protected] |
|
MAIL_FROM_NAME="Jack" |
|
-------------------------------------------------------------- |
|
----> Testing email service is working or not |
|
Route::get('/test-mail', function () { |
|
try { |
|
Mail::raw('Test Email!', function ($message) { |
|
$message->to('[email protected]')->subject('Testing mails'); |
|
}); |
|
echo "Sent..."; |
|
} catch(Exception $e) { |
|
echo $e->getMessage(); |
|
} |
|
dd('test mail'); |
|
}); |
|
|
|
growl("@lang('boilerplate::chatbottemplate.list.deletesuccess')", "success"); |
|
growl("@lang('boilerplate::chatbottemplate.list.deleteerror')", "error"); |
|
|
|
-------------- Making visible or hidden attributes from Eloquent temporarily ---- |
|
|
|
$users = $users->makeVisible(['address', 'phone_number']); |
|
$users = $users->makeHidden(['address', 'phone_number']); |
|
|
|
------------------------- update current timestamps - migration - -------- |
|
$table->timestamp('created_at')->useCurrent(); |
|
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate(); |
|
----------------------- Download Image from url ----------------------- |
|
|
|
var download_url = "image_url_link_paste_here.jpg"; |
|
|
|
fetch(download_url) |
|
.then(res => res.blob()) |
|
.then(blob => { |
|
console.log(blob); |
|
var url = window.URL || window.webkitURL; |
|
var link =url.createObjectURL(blob); |
|
var a = $("<a />"); |
|
var file_name = download_url.split('/').pop() |
|
a.attr("download", file_name); |
|
a.attr("href", link); |
|
$("body").append(a); |
|
a[0].click(); |
|
$("body").remove(a); |
|
}); |
|
|
|
------------ Datatable ordering remove/false ------- |
|
|
|
"ordering": false, |
|
|
|
-------------------- datatable - ajax callback get ------------------------- |
|
|
|
ajax: { |
|
url: '{!! route('boilerplate.users.datatable') !!}', |
|
type: 'post', |
|
dataSrc: function(d){ |
|
closeSwalWhilePageLoaded(); |
|
return d.data; |
|
} |
|
}, |
|
|
|
------------------------------ |
|
chromium Puppettier - cheet sheet |
|
//https://stackoverflow.com/questions/59112956/cant-use-puppeteer-error-failed-to-launch-chrome |
|
|
|
sudo apt install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget |
|
|
|
|
|
---------------------- Cloning mysql database ---------- |
|
|
|
1> sudo mysql -> create database new_db_name; //create new database |
|
2> mysqldump old_db_name | mysql new_db_name // single command - mysql dump and copy to new db |
|
|
|
|
|
--------------------- mysql dump of load from existing db -------- |
|
|
|
1> sudo mysql -> create database new_db_name; //create new database |
|
2> mysql new_db_name --force < db_name.sql //clone database from file |
|
|
|
|
|
--------------------Generate random token ---------------------------- |
|
|
|
$token = (string) Str::uuid(); |
|
|
|
------------------ Call another controller method -------------------------- |
|
|
|
//Calling a method that is from the OtherController. |
|
$result = (new OtherController)->method(); |
|
|
|
|
|
---------------- date format converstion model ----------- |
|
|
|
|
|
protected $casts = [ |
|
'purchase_order_date' => 'date:d-m-Y', |
|
]; |
|
|
|
--------------------- Laravel Javascipt jquery - route - with parameter generate ----------- |
|
|
|
var url = '{{ route("admin.stocks.edit", ":id") }}'; |
|
url = url.replace(':id', stock.id); |
|
|
|
|
|
------------ Appdend Dynmic options ------------ |
|
|
|
$(this).append($('<option>', {value: que_id, text: col_name})); |
|
|
|
----------------- datatable - defauly length - 50 ---------- |
|
"iDisplayLength": 50, |
|
|
|
|
|
------------index of array jquery ------------- |
|
var index = array.indexOf(item); |
|
if (index !== -1) { |
|
array.splice(index, 1); |
|
} |
|
-------------- Get MultiCHeckbox Value ----------------- |
|
|
|
var multicheck_box_array = document.getElementsByName("choice_ans_list_457[]"); |
|
var multicheck_boxes_length = chk_arr.length; |
|
|
|
for(k=0;k< multicheck_boxes_length;k++) |
|
{ |
|
if(multicheck_box_array[k].checked){ |
|
console.log(multicheck_box_array[k].value); |
|
} |
|
} |
|
|
|
------------- object length find -------------------- |
|
|
|
Object.keys(found_que_info_object.data).length; |
|
|
|
---------------- Carbon now -------------------- |
|
Carbon::now()->format('Y-m-d H:i:s') -> 2021-12-27 00:00:00 |
|
Carbon::now()->toTimeString() // 12:50:30 |
|
|
|
----------------------------------- Create laravel project with version ----------------- |
|
|
|
composer create-project laravel/laravel="5.6.*" dragAndDrop --prefer-dist |
|
|
|
|
|
------------ check select value present or not -------------------------------------------- |
|
|
|
var exists = 0 != $('#select-box option[value='+ 5 +']').length; |
|
|
|
--------------- Laravel Drag And Drop -------------------------- |
|
|
|
1. Datatable -> //https://www.nicesnippets.com/blog/laravel-6-drag-and-drop-datatable-rows-for-sorting-example |
|
2. ul/li -> //https://www.nicesnippets.com/blog/drag-and-droppable-cards-using-laravel-6-jquery-ui-example |
|
|
|
-------------------------- time replacement carbon -------------- |
|
|
|
//greeting message time replacement |
|
$replace_greeting_time = Carbon::now(); |
|
$replace_greeting_time = $replace_greeting_time->format('h:i a'); |
|
|
|
----------------- whereIn query - get result by id order maintain ----------- |
|
|
|
$ids_ordered = implode(',', $templateQuestionIds); |
|
$chatbotQuestions = ChatbotQuestion::whereIn('id', $templateQuestionIds) |
|
->orderByRaw("FIELD(id, $ids_ordered)") // this line is magic |
|
->with('type') |
|
->get(); |
|
|
|
|
|
------------------------ Select2 Title issue fixes - jquery UI ------------------------------- |
|
|
|
//removem title on hover - jquery UI changes - its showing title as tooltip so |
|
$(document).on('mouseenter', '.select2-selection__rendered', function () { |
|
$(this).removeAttr('title'); |
|
}); |
|
|
|
------------------ Datatable - DEfault Value showcase - if its null ------------------------- |
|
|
|
"columnDefs": [{ |
|
"defaultContent": "-", |
|
"targets": "_all" |
|
}], |
|
|
|
-------------- updateOrCreate (first array -> match condtion -> 2nd value input) ------------------------------ |
|
$chatbotQuestion = ChatbotQuestion::updateOrCreate([ |
|
'chatbot_id' => $input['chatbot_id'], |
|
'question_type_id' => $input['question_type_id'] |
|
], $input); |
|
|
|
---------------------- Validator message change laravel validate ---------------- |
|
|
|
$customMessages = [ |
|
'url.required' => 'Url is required', |
|
'recovery_code' => 'required|exists:users,email_recovery_code', |
|
'email' => 'required|email|unique:users,email', |
|
// 'date.required'=>'Date is required', |
|
]; |
|
$this->validate($request, ['url' => 'required'], $customMessages); |
|
|
|
-------------- find index from jquery array - by key name ---------------- |
|
findWithAttr(question_type_list, 'id', 'asd'); |
|
function findWithAttr(array, attr, value) { |
|
for(var i = 0; i < array.length; i += 1) { |
|
if(array[i][attr] === value) { |
|
return i; |
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
|
|
---------Select Onchange--------------------------- |
|
|
|
$( "#filter_id" ).change(function() { |
|
console.log(this.value); |
|
}); |
|
|
|
---------formdata - image upload with data--------- |
|
|
|
var formData = new FormData(); |
|
formData.append('question_text', $('input[name=question_text]').val()); |
|
|
|
if($('input[name=corona_image]')[0].files[0]){ |
|
formData.append('corona_image', $('input[name=corona_image]')[0].files[0]); |
|
}else{ |
|
alertify.error('Please Upload Your Corona Sample Image', 5, function(){ console.log('dismissed'); }); |
|
return true; |
|
} |
|
|
|
$.ajax({ |
|
type: "POST", |
|
url: '{{ route("boilerplate.chatbots-questions.store") }}', |
|
data: formData, |
|
processData: false, // tell jQuery not to process the data |
|
contentType: false, // tell jQuery not to set contentType, |
|
dataType: "json", |
|
success: function(data) { |
|
|
|
}, |
|
error: function(xhr){ |
|
} |
|
}); |
|
|
|
----------------------- Store Image to Storage ---------------------------------------- |
|
|
|
$attachment = isset($input["image"]) ? $input["image"] : ""; |
|
if (!empty($attachment)) { |
|
// $file = $input->file('corona_image'); |
|
$attachment_name = 'sample_' . Carbon::now()->timestamp . str_random(2) . '_' . $attachment->getClientOriginalName(); |
|
$destinationPath = storage_path('app/public'); |
|
$attachment->move($destinationPath, $attachment_name); |
|
unset($input["image"]); |
|
//image related paths |
|
$filePath = url('storage/'.$attachment_name); // 127.00.00.0:8000/..../jack.jpeg |
|
$input['image_path'] = $attachment_name; //jack.jpeg |
|
$input['filepath'] = storage_path('app/public/' .$attachment_name); //var/www/html .... |
|
} |
|
---------------------------------- Enter click keyboard - click on button ------------------------------ |
|
|
|
$(document).on('keypress',function(e) { |
|
console.log(e.target); |
|
if(e.which == 13) { |
|
e.preventDefault(); |
|
if(e.target.id == 'question_text' || e.target.id == 'question_error_text') { |
|
$(".save_new_question").click(); |
|
}else if(e.target.id == 'reference_link_text'){ |
|
$(".btn-save-reference").click(); |
|
} |
|
console.log('perssed'); |
|
} |
|
}); |
|
-------------------------- add 1st column as Index number - 1,2,3..... ---------------------------------- |
|
|
|
oTable.on( 'order.doTable search.dt', function () { |
|
oTable.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) { |
|
cell.innerHTML = i+1; |
|
} ); |
|
} ).draw(); |
|
|
|
-------------------------- Subquery with child table (whereHas)-------------------- |
|
|
|
$last_sequence_number = ChatbotQuestion::where('chatbot_id', $request->chatbot_id) |
|
->whereHas('type', function ($query) { |
|
$query->where('key_name', 'email_phone'); |
|
})->pluck('sequence_order')->toArray(); |
|
|
|
$users = $students = User::whereHas( |
|
'roles', function($q){ |
|
$q->where('name', 'company_user'); |
|
} |
|
)->get(); |
|
|
|
--------------------- Find index of column -------------------------- |
|
|
|
$questionTypes = QuestionType::all(); |
|
$greetingsColumnIndex = ($questionTypes->where('key_name', 'greetings')->pluck('id')->toArray())[0]; |
|
|
|
|
|
-------------------- Javscript chat time convert like 1:24 PM, 10:40 AM ------------ |
|
|
|
function tConvert (tim_val) { |
|
try { |
|
// Check correct time format and split into components |
|
time = tim_val.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [tim_val]; |
|
|
|
if (time.length > 1) { // If time format correct |
|
time = time.slice (1); // Remove full string match value |
|
time[5] = +time[0] < 12 ? 'AM' : 'PM'; // Set AM/PM |
|
time[0] = +time[0] % 12 || 12; // Adjust hours |
|
} |
|
time[3] = ' '; // removed seconds - if want then remove this |
|
return time.join (''); // return adjusted time or original string |
|
} catch (error) { |
|
return time.substring(0, 5); |
|
} |
|
} |
|
|
|
----------------------- Query Paramter Search - Javascript ----------------------- |
|
|
|
const urlSearchParams = new URLSearchParams(window.location.search); |
|
const params = Object.fromEntries(urlSearchParams.entries()); |
|
if (typeof(params.id) != 'undefined') { |
|
dataTableFetchRoute += '?id=' + params.id; |
|
} |
|
|
|
?> |