Skip to content

Instantly share code, notes, and snippets.

View rakeshsoni18's full-sized avatar
🎯
Focusing

Rakesh Soni rakeshsoni18

🎯
Focusing
View GitHub Profile
@rakeshsoni18
rakeshsoni18 / Multiple Auth Guard
Created March 11, 2022 10:12
Multiple Auth Guard
https://pusher.com/tutorials/multiple-authentication-guards-laravel/#admin-model
@rakeshsoni18
rakeshsoni18 / Configuration of Supervisor in ubuntu
Created February 10, 2022 07:25
Configuration of Supervisor in ubuntu
Tutorial link
https://youtu.be/r9HKfJFDEFE
Step 1:-
sudo apt-get install supervisor
Step 2:-
Now go to following path
cd /etc/supervisor/conf.d
@rakeshsoni18
rakeshsoni18 / What does this symbol mean in PHP?
Created February 9, 2021 09:57
What does this symbol mean in PHP?
https://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php?rq=1
@rakeshsoni18
rakeshsoni18 / Redirect HTTPS Through .htaccess
Created October 22, 2020 09:41
Redirect HTTPS Through .htaccess
# Forcing HTTPS on All Traffic
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Forcing HTTPS on a Specific Domain
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain1.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
@rakeshsoni18
rakeshsoni18 / Image Preview Jquery
Created September 17, 2020 11:43
Image Preview Jquery
<img src="{{ asset('default-image-thumbnail.jpg') }}" alt="product-image" id="imageThumbnail" width="100%" height="170">
// PRODUCT IMAGE PREVIEW
$('#product_img').on('change', function () {
var file = $(this).get(0).files;
var reader = new FileReader();
reader.readAsDataURL(file[0]);
reader.addEventListener('load', function (e) {
var image = e.target.result;
$('#imageThumbnail').attr('src', image);
@rakeshsoni18
rakeshsoni18 / Get Accurate IP Address
Created July 22, 2020 12:43
Get Accurate IP Address
function get_ip_address(){
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key){
if (array_key_exists($key, $_SERVER) === true){
foreach (explode(',', $_SERVER[$key]) as $ip){
$ip = trim($ip); // just to be safe
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false){
return $ip;
}
}
$collection = collect([
[
'price' => 2561,
'tax' => 50
],
[
'price' => 3500,
'tax' => 100
]
]);
@rakeshsoni18
rakeshsoni18 / Assessor and Mutators
Created June 10, 2020 13:15
Assessor and Mutators
function getNameAttribute($value){
return strtoupper($value);
}
App\Dogs::find(2)->name; // result "JOCK"
That's a nice way to format database records before they hit the page, although it means that name will always be formatted that way (you can use ->getOriginal('name') if you need to see it without the formatting).
Here's a little secret, though. Add this to your Dogs model:
@rakeshsoni18
rakeshsoni18 / Retry After an Exception in a PHP Try-Catch Block
Created June 10, 2020 13:11
Retry After an Exception in a PHP Try-Catch Block
/**
* Basic structure for retrying when an exception is thrown in a try/catch block.
* This example fails through three retries simply to illustrate the behavior.
*/
$retries = 3;
for ($try = 0; $try < $retries; $try++) {
try {
throw new \Exception('bad mojo');
} catch (\Exception $e) {
var_dump('failed ' . $try);
@rakeshsoni18
rakeshsoni18 / gist:42d2c877258f244fbea182ba23ceb061
Last active May 29, 2020 17:22
Collection Map Column Change
https://stackoverflow.com/questions/43711940/laravel-collection-using-map-and-contains
$list = collect($list)->map(function($x){
return [
'Name' => $x->fname. ' ' .$x->lname,
'Gender' => $x->gender,
'Designation' => $x->designation,
'Experience' => $x->exp_year,
'Preferred Location' => $x->preferred_location,
'Expected Salary' => $x->expected_salary,