Categories
General Laravel

Laravel : Helpful Gems, Shortcuts Syntax and Many More

In our regular development life we are trying to do more better and efficient code. But the thing is that many developers don’t know the proper shortcuts & efficient helpers and many more things which helps to make more better coding. I listed here some shortcut of syntax which are helpful for you.

Common Syntax Vs Shorter Syntax

Some of Laravel Eloquent hidden gems

  • Conditional DB Query

Sometimes we need conditional query but when the both result (or none ) returns true, then we generally do separate eloquent calls as like  

Another better way to repeat eloquent call

  • Use where() on a with() by using whereHas()

If you want to need of constraints on models’s relationship then return those result whose relationship match that constraint,  hahahahah… It’s much better solution

->whereHas() checks that 

  • The relationship exists
  • Allows you to pass a closure that you can use to add constraints to the query being called
  • Using the shorter where method for date column

The below method is most important, it’s a recommendation to use those filter for date column intend of where clauses or looping through the returned collection to breakdown the date and grab only ones from a particular month.

  • Only return models if they have a particular relationship using has().

The below example says required ->has(‘specification’) means return those eloquent model whose records exist in DB. 

  • Use of (skip / take) instead of offset and limit

To limit the number of results returned from the query or to skip a given number of results in the query. It is easy to read & sort as like skip(10) users and take(5) 

Categories
Laravel Uncategorized

Laravel Certification

   It’s a great opportunity… 

Stand out. Get Certified

Yaaaa, You can become globally recognized certified developer or the certified team for your expertise in creating modern web applications with Laravel. The Board of Advisors provides good knowledge & high-quality exams. For more information related links are here.

Certified Developer


Stand out in a stack of resumes. Differentiate yourself from your peers by proving your in-depth Laravel knowledge.

Certified Team


Your company has the best Laravel experts. Do your customers know it? Certify your team and gain your customer’s trust.

 

Related Links – 

Laravel Certification

laravel-news

Categories
Angular Laravel PHP

Instamojo Payment Gateway

 Instamojo is a free Payment Gateway for 5,00,000+ Businesses in India. There is no setup or annual fee for this payment gateway. Just pay a transaction fee of 2% + ₹3 for the transactions. Instamojo accepts Debit Cards, Credit Cards, Net Banking, UPI, Wallets, EMI, NEFT and IMPS.

Instamojo.com is a digital payments platform bundled with tons of e-commerce features to enable any business or individual to sell, manage & grow effortlessly, securely and cost-effectively.

It was not easy to make it work in India because most of the payments are handled through credit card and PayPal and very few Indians use them. Then after RBI regulations even using PayPal within India was impossible.

Follow the given steps for easy Integration in Laravel,

Instamojo PHP API

Assists you to programmatically create, edit and delete Links on Instamojo in PHP.

Installing via Composer –

$ php composer.phar require instamojo/instamojo-php

Note: If you’re not using Composer then directly include the contents of src directory in your project.

And visit this link for its usage.

Further documentation is available at https://docs.instamojo.com/v1.1/docs


Categories
Laravel

Whats new in Laravel 5.7.15 ?

Laravel 5.7.15 is available with a new Eloquent relationship getters and validation rules

Eloquent relationship getters:

  • BelongsToMany::getParentKeyName
  • BelongsToMany::getRelatedKeyName
  • HasManyThrough::getFirstKeyName
  • HasManyThrough::getForeignKeyName
  • HasManyThrough::getSecondLocalKeyName
  • HasOneOrMany::getLocalKeyName
  • MorphToMany::getInverse

Validation Rules:

  • starts_with – allows you to validate start of input strings

For example:

$request->validate([   

   ‘greeting’ =>’starts_with:hello,hi;

]);

And date_equals validation rule is now translatable

For example:

‘date_equals’ => ‘The :attribute must be a date equal to :date.’,

Categories
General Laravel

Deep Diving with Laravel – Queue System

It’s a detail information of Laravel queue system with step by step working,  

Queue System  : – Laravel is shipped with a built-in queue system that helps you run tasks in the background & configure how the system should react in different situation using a very simple API.

Check out the full documentation for more information.

Laravel Queue ,   Queue system 

Monitoring Queue (Laravel Horizon) :-  Laravel Horizon is a queue manager that gives you full control over your queues. It provides means to configure how your jobs are processed, generate analytics, and perform different queue-related tasks from within a nice dashboard

Check out the full documentation for more information.

Laravel Horizon,   The Horizon

Categories
Laravel PHP

Laravel Paytm Integration

Paytm is a very popular Indian payment gateway. Pay money via paytm is very easy. They provides easy way for the shopping and manage your money in your paytm wallet. In this post i will explains you, how to integrate Paytm payment gateway in our Laravel application online using Paytm_Web_Sample_Kit_PHP  example available on github.  

How to install the sample kit on a web server:

  1. First, download Paytm_Web_Sample_Kit_PHP  folder available on github..
  2. Copy PaytmKit folder in document root of your server (like /var/www/html)
  3. Open config_paytm.php file from the PaytmKit/lib folder and update the below constant values
    • PAYTM_MERCHANT_KEY – Provided by Paytm
    • PAYTM_MERCHANT_MID – Provided by Paytm
    • PAYTM_MERCHANT_WEBSITE – Provided by Paytm
  4. PaytmKit folder is having following files:
    • TxnTest.php – Testing transaction through Paytm gateway.
    • pgRedirect.php – This file has the logic of checksum generation and passing all required parameters to Paytm PG.
    • pgResponse.php – This file has the logic for processing PG response after the transaction processing.
    • TxnStatus.php – Testing Status Query API

For Offline(Wallet Api) Checksum Utility below are the methods:

  1. getChecksumFromString : For generating the checksum
  2. verifychecksum_eFromStr : For verifing the checksum

To generate refund checksum in PHP :

  1. Create an array with key value pair of following paytm parameters (MID, ORDERID, TXNTYPE, REFUNDAMOUNT, TXNID, REFID)
  2. To generate checksum, call the following method. This function returns the checksum as a string. getRefundChecksumFromArray($arrayList, $key, $sort=1)

Start Building with Paytm

  1. Create account or login using your existing Paytm account.
  2. Generate your staging account credentials from the dashboard. These are required to explore Paytm integration solutions.
  3. When you are ready to go live, activate your account in the dashboard to get production account credentials

Account credentials are available in your dashboard for both staging and production environment. These credentials consist of –

  1. MID (Merchant ID) – This is a unique identifier provided to every merchant by Paytm. MID is part of your account credentials and is different on staging and production environment. Your staging MID is available here and production MID will be available once your activation is complete.
  2. Merchant Key – This is a unique secret key used for secure encryption of every request. This needs to be kept on server side and should not be shared with anyone.

Note : Paytm Payment Gateway provides a secure, PCI-compliant way to accept Debit/Credit card, Net-Banking, UPI and Paytm wallet payments from your customers.

Categories
Laravel PHP

Razorpay Payment Gateway Integration for Laravel 5+

Currently several payment gateways are available for online payments like Paypal, Stripe, CCAvenue and many more. For Indian market,  Razorpay is best for make online payment due its simplicity.

Follow the given steps for easy Integration,

Create Razorpay Account

To create Razorpay account , click this link Razorpay Account,and get your razor_key and razor_secret from the account.


 Install package : Razorpay

Next, we need to install razorpay/razorpay laravel package in our application by running following command using composer.

composer require razorpay/razorpay:2.*

And visit this link for its usage.

Categories
Laravel PHP

PHP Library to write XLSX files

Excel is used to store large amount of information in the form of a spreadsheet. Which is easy to manage accounts information and other information. Now a day’s we save large amount of information online in database but some times we need to convert that information into excel spreadsheet and provides to user. In this post i will explains you, how to create excel file online using PHP_XLSXWriter library available on github. You can download this from the link : https://github.com/mk-j/PHP_XLSXWriter

This library is designed to be lightweight, and have minimal memory usage.

It is designed to output an Excel compatible spreadsheet in (Office 2007+) xlsx format, with just basic features supported:

  • Supports PHP 5.2.1+
  • Takes UTF-8 encoded input
  • Multiple worksheets
  • Supports currency/date/numeric cell formatting and simple formulas
  • Supports basic cell styling
  • Supports writing huge 100K+ row spreadsheets

Below are a few test cases, writing large xlsx spreadsheet files with PHPExcel and PHP_XLSXWriter for comparison.

Case

PHP_Excel

PHP_XLSXWriter

10 columns, 10,000 rows in 4 sheets (400,000 cells)

File size : 458MB

Execution time : 101.55s

File size : 11MB

Execution time : 7.56s

10 columns, 10,000 rows in 6 sheets (600,000 cells)

File size : 658MB

Execution time : 202.72s

File size : 15MB

Execution time : 11.31s

10 columns, 20,000 rows in 4 sheets (800,000 cells) File size : 912MB

Execution time : 301.31s

File size : 22MB

Execution time : 14.94s

 

In a few simple tests, PHP_XLSXWriter shows a 98% savings on memory and 95% savings on time when compared to PHP_Excel for writing large files. Though PHP_Excel may have more features, it doesn’t compare with PHP_XLSXWriter when it comes to performance.

Simple PHP CLI example:

$data = array(
    array('year','month','amount'),
    array('2003','1','220'),
    array('2003','2','153.5'),
);

$writer = new XLSXWriter();
$writer->writeSheet($data);
$writer->writeToFile('output.xlsx');

Note : PHP_XLSXWriter is simple to create lightweight excel spreadsheet using PHP library.
Categories
Laravel

YesAuthority – Laravel Routes Authorization Library

If you want to add a permission on the basis of Laravel routes then YesAuthority authorization library is very useful to do so. Spatie, Bouncer and other many more libraries are available for Laravel authorization, but these libraries uses Laravel Eloquent models to set up permissions and ability. In YesAuthority you can allow / deny permission from single file, you can statically define your rules in yes-authority.php or you can define your rules in Database for dynamic permissions. You can simply add following syntax to check the route is accessible or not.

Syntax :

canAccess(‘test.route.name’);

// true

 

For more information visit at –

https://livelyworks.github.io/YesAuthority/,

https://github.com/livelyworks/YesAuthority

Categories
Laravel

Laravel 5.5 LTS

The laravel 5.5 (LTS) officially released, With new ideas and improvements, a lot of things. Here are some highlighted features in this video

 

Here are some laravel 5.5 LTS related links

Release Notes

What’s new in laravel 5.5 series

Laravel 5.4 to 5.5 – Upgrade Guide

All tutorials & news & all about