Posts

Laravel Validation - Unique rule with multiple column and condition.

Today I am going to share, How we can use Laravel validation rule `unique`. If you have worked with laravel and familiar with laravel validation, you must know what does 'unique' rule checks. If not let me give here a brief about this. In simple words, It is similar to a unique key constraint applied to a column in the database table. 'Unique' rule check there is no similar value exists in the given database table column, to value matching with the provided input value. The general format of the rule is: unique:table //when input name is similar to column name OR unique:table,column OR unique:Model,attribute Examples: 'email' => 'unique:users' //here users is table name OR 'email' => 'unique:c,email_address' //can give custom column name. OR 'email' => 'unique:User,email'  //here User is a model class This is a very simple usage ...

Get Free SSL Certificate from Let’s Encrypt for your website - Linux, Apache, EC2, Heroku.

Image
To enable HTTPS on your website, you need a certificate from a Certificate Authority (CA). Let’s Encrypt is a nonprofit Certificate Authority providing Free SSL certificates to 225 million websites.  You can also get a (absolutely) free SSL certificate using Certbot. Certbot is open-source software tool recommended by Let's Encrypt to for automatically deploy SSL certificate. This certificate is as valid as a paid certificate. There are two ways to get and install certificate on your server. 1. When you have SSH access to your server. Then you have option to Generate and Deploy SSL certificate automatically by installing Certbot on your server. 2. When you are using a platform like Heroku (Paas) where you don't have SSH access to your server directly and can't install any package on it. In this case you can install Certbot at your local system (Linux) using below commands and use it only to generate certificate files. Later you can Deploy them manually. Install Certbot a...

LEAST() and GREATEST() - Postgres SQL Amazing But Rarely Known Functions .

PostgresSQL is very powerful and one of the world's most advanced open-source relational databases. It gives much more flexibility and customization on query level when you want to perform a complex operation or complex queries on the database. Postgresql provides multiple operators and functions which make even complex operations and complex queries pretty easy and simple. Similarly LEAST() and GREATEST() are functions that make your work very easy and simple. LEAST() and GREATEST() functions are very useful when you want to operate on different columns within the same row (a record) in a table. LEAST() and GREATEST() compare and find the minimum and maximum value respectively among given columns values in the same row. It's similar to finding a minimum or maximum value from an array of given values. Here are a few simple examples you can try: select LEAST(5, 3, 9, 2, 8, 1) and GREATEST(5, 3, 9, 2, 8, 1); //should give 1 and 9 respectively In-case of String or Varchar, it gi...

How to Apply SSL Certificate (non-self) on EC2 with Linux/Ubuntu having Apache Server.

Assuming you are well aware of What is an SSL certificate? Why we need it? here I am going to guide you for How you can apply an SSL certificate for your website hosted on Linux or Ubuntu Server using Apache 2 server. You can either purchase a new SSL certificate or can generate it for free on  sslforfree.com  which authorized by  Letsencrypt  the first non-profit CA. After Purchasing or getting your SSL certificate you have actually 2 SSL files, Certificate and Private Key. You can upload both SSL files (certificate.crt and private.key) on the server: Create a new folder in Directory `/home/user-name/.ssh`. Create or upload files certificate (.cert) file as certificate.crt and Private key (.key) as private.key in the folder created earlier. Now edit Virtual Host configuration for the website for which you want to apply the SSL certificate. sudo nano /etc/apache2/sites-enabled/{yourwebsitedomain.com}.conf Add the following code to website vhost config...

How to Block Inspect Element and Right Click on Your Website using Simple JavaScript

Assuming you are well aware of What is an SSL certificate? Why we need it? here I am going to guide you for How you can apply an SSL certificate for your website hosted on Linux or Ubuntu Server using Apache 2 server. You can either purchase a new SSL certificate or can generate it for free on  sslforfree.com  which authorized by  Letsencrypt  the first non-profit CA. After Purchasing or getting your SSL certificate you have actually 2 SSL files, Certificate and Private Key. You can upload both SSL files (certificate.crt and private.key) on the server: Create a new folder in Directory `/home/user-name/.ssh`. Create or upload files certificate (.cert) file as certificate.crt and Private key (.key) as private.key in the folder created earlier. Now edit Virtual Host configuration for the website for which you want to apply the SSL certificate. sudo nano /etc/apache2/sites-enabled/{yourwebsitedomain....

How to Lead - All You Need to Know to be A Good Leader

Image
There is no specific field/domain (development, marketing, management, etc.) to become a leader and you don't need to wait for an opportunity for the same. Leadership can be observed in any field/domain in any small or big tasks. But there are few observations of a good leader. Observations on Leadership 1. No Single type of personality for leadership : The is not any particular type of person who is only able to lead. Anyone can become a good leader no matter what kind of personality you have. You do not need to look like or copy anyone great leader, just be yourself. 2. Three Fundamental Attributes :       -  Great leader thinks and communicate clearly : Simple and clear communication actually needs your thought process and time. Take some spare time, write down your thoughts then think about how to make them more simple and clear to communicate.       It always pays you back to communicate clearly.       -  Good Judge...

How to Show Cookie Policy Consent or GDPR Popup in Laravel using Cookie.

Cookie in Laravel You can use the cookie in Laravel using the Helper method ` cookie() ` or method available with Request/Response Object or `Cookie` facade. $request->cookie('name'); OR use Illuminate\Support\Facades\Cookie; Cookie::get('name'); To get more clarity on how to use the cookie in Laravel with an example to show cookie consent popup on your Laravel website and hide/remove it once you accept the policy. Cookie Policy Consent Popup in Laravel First, create and a Cookie Consent popup as notification to the footer section of your Laravel main blade template file.  <div class="cookies-block">         <h5>This website uses cookies</h5>         <p>We use cookies to improve your experience and deliver personalised content. By using this website, you agree to our <a href="javascript:void()">Cookie Policy</a>.</p>         ...

How to Write Redirect Rules for HTTP to HTTPS in Apache using .htacess

HTTP vs HTTPS HTTP (HyperText Transfer Protocol) is the most basic and known protocol (a standard set of rules) used to transfer data from a web server to a browser. It allows communication between different systems. HTTPS is HTTP with encryption i.e it uses encryption (TLS/SSL) to make HTTP requests more secure while transferring the data from a web server to a browser or vice-versa.  So there are benefits of using HTTPS for your website: 1. It makes your website more secure against data theft. 2. It also improves your SEO rank. So now let's learn how we can direct a website from HTTP to HTTPS. First, make sure you have generated and integrated SSL certificate for your website and the Rewrite module is enabled on your hosting server. so that your website can work on HTTPS without any trouble. After applying the SSL certificate our website can be accessed via HTTP or HTTPS. But per above after knowing the benefits of HTTPS we need redirect HTTP to HTTPS. ...

Ways to Pass Parameters to Laravel job.

There are 2 ways to pass parameters to a dispatching job in Laravel. First is simply call dispatch() or dispatchNow() as per requirement on your Job class like calling a static method on a class: YourJob::dispatch(argument1, argument2, argument3); Second is simply pass arguments while creating an instance/object of Job class then pass the object to dispatch method(always available in the controller) like: $this->dispatchNow(new YourJob(argument1, argument2, argument3)); The arguments will be available in the constructor, can you assign them to class local variable properties and use anywhere in Job class. Let consider below example job: <?php namespace App\Jobs; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; class Testjob imple...

Important things every developer need to know about Database Indexing

Assuming you know the basics of Database and know the definition of indexes used in DB, here are some important things about Database indexes about which every good developer must aware of: DB Indexing is used to read data faster, but it makes writing slower. Indexes use in-memory data structures. Indexes use B-Tree (Balanced Tree) data structure to store data and use Binary search for reading/searching. It always saves corresponding DB internal row-id (not table PK) with every indexed node in the B-tree It is not good to add an index to each column of a table. If you have applied index on certain column but in query use any function on an indexed column, the index will not help at all. You can create a combined index on multiple columns. Order matters as per query need. To understand the use of indexes or to know if the query is actually taking the benefit of your index on your column use Explain. Explain give you the execution plan of the query. Explain give you info abou...