Skip to content

Instantly share code, notes, and snippets.

View abdullahbutt's full-sized avatar

Abdullah Butt abdullahbutt

  • Fulda, Deutschland
View GitHub Profile
@abdullahbutt
abdullahbutt / Multi Language API Response Messages In Laravel
Created September 26, 2018 14:00
Multi Language API Response Messages In Laravel
Multi Language API Response Messages In Laravel
https://medium.com/teknomuslim/multi-language-api-response-messages-in-laravel-5c9029a32e5c
When providing API Service, sometimes we need to set multiple language for handling response. For example, for servicing mobile apps that has multi language support, user needs to get proper active language message in their app. We do not want user who already set Indonesian as current app language but get an English language in response message.
How to Accomplish Dynamic Language?
Laravel provides multi language support. Simplest thing is define language using request header.
@abdullahbutt
abdullahbutt / laravel check current page route
Created October 6, 2017 10:22
laravel check current page route
//To match Route Alias with current page
@if(Route::current()->getName() == 'new.cart.checkout')
@endif
//OR
@if (\Route::current()->getName() =='plan.selection')
@abdullahbutt
abdullahbutt / php years range
Created October 6, 2017 10:01
php years range
<?php
$years = range(date("Y"),date("Y")+15);
var_dump($years);
/*
// If current year is 2017, Result will be below:
array(16) {
@abdullahbutt
abdullahbutt / swift bmi calculator.playground
Last active April 16, 2020 15:20
swift bmi calculator
//: Playground - noun: a place where people can play
/*
The body mass index (BMI) is a measure used to quantify a person’s mass as well as interpret their body composition. It is defined as the mass (Kg) divided by height (m) squared.
Here’s the BMI calculation formula:
BMI = mass (kg) / height (m2) // Metre square
If the BMI is greater than 25, use the print statement to tell the user that they are overweight.
Otherwise, if the BMI is between 18.5 - 25, tell the user that they are of normal weight.
@abdullahbutt
abdullahbutt / credit_card_masking.blade.php
Last active July 11, 2017 13:14
credit cart masking html
<div class="field-holder">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12 field required">
<label for="ccnum">Credit Card Number</label>
<input type="text" id="card-number" placeholder="Credit Card Number" required = "required" data-inputmask="'mask': '9999-9999-9999-9999'" maxlength="19" title="Credit Card Number" >
{{-- Form::text('card-number','', ['id' =>'card-number','placeholder'=>'Credit Car Number (12 digits)*','required' => 'required', 'maxlength' => '12']) --}}
</div>
</div>
</div>
@abdullahbutt
abdullahbutt / move cursor to focus on first html validation input error field
Last active July 5, 2017 07:50
move cursor to focus on first html validation input error field
<!--
http://jsfiddle.net/LL5S6/44/
-->
<header>This is the header</header>
<div>
<form action="#">
<input type="text" name="test" placeholder="write your first name" required />
<br />
<br />
<input type="text" name="test2" placeholder="write your last name" required />
@abdullahbutt
abdullahbutt / ternary operator blade if else on single line
Created July 4, 2017 12:46
ternary operator blade if else on single line
How to make if else statement on a single line in a blade? How to compress the below on to a single line.
@if ($var === "hello")
Hi
@else
goodbye
@endif
Solution:
@abdullahbutt
abdullahbutt / laravel alpha space validation rule
Last active December 5, 2018 01:16
laravel alpha space validation rule
In Laravel 5.4, I used the following way to define a alpha_spaces rule:
You can create a custom validation rule for this since this is a
pretty common rule that you might want to use on other part of your app
(or maybe on your next project).
--------------------------------------------------------------------------------------------
on your app/Providers/AppServiceProvider.php
// Add below validator Namespace on top of file:
@abdullahbutt
abdullahbutt / image.html
Created May 11, 2017 07:03
display image in browser on image upload
<div class="row">
<div class="col-xs-12 col-lg-8 col-lg-offset-2">
<label class="col-sm-4 col-xs-12 control-label">Upload Images</label>
<div class="col-xs-12 col-sm-8">
<div class="form-group">
{{-- Form::textarea('description','', ['class' => 'form-control form-control-solid placeholder-no-fix', 'rows'=>'5', 'cols'=>'20','placeholder'=>'Description', 'maxlength' => '2000']) --}}
<label class="f-label">Upload a New Image</label>
<input type="file" name="images[]" id="upload-image" multiple style="display:none" />
<div id="upload" class="drop-area">
Upload File
@abdullahbutt
abdullahbutt / composer timeout issue fix
Created March 23, 2017 12:25
composer timeout issue fix
How To Stop PHP Composer Timing Out When Using "composer update" or "composer install"
https://ilikekillnerds.com/2014/07/how-to-stop-php-composer-timing-out-when-using-composer-update-or-composer-install/
At work our internet connection is painfully slow for the moment while we sort something better out and I ran into a rather interesting quirk whilst using Composer and timeouts.
I was trying to install Laravel and because of the sheer number of components it got part of the way through and then would display some error message about exceeding the timeout limit of 300 seconds (5 minutes).
The reason for this appears to be due to the fact my Internet connection is mega slow and some components being largish in size. When calling composer update or composer install you just need to specify a higher timeout value.