Thursday, 24 January 2019

Laravel Method to check if the given record id exists on DB table or not.

public function isModelRecordExist($model, $recordId)
{
    if (!$recordId) return false;

    $count = $model->where(['id' => $recordId])->count();

    return $count ? true : false;
}

// To Test
$recordId = 5;
$status = $this->isModelRecordExist( (new MyTestModel()), $recordId);

// Outcome: true | false

Hope it helps!

Thursday, 29 November 2018

Docker machine creation - Too many retries waiting for SSH to be available -Maximum number of retries (60) exceeded

Docker machine creation - Too many retries waiting for SSH to be available -Maximum number of retries (60) exceeded

To resolve the issue for 
Error creating machine: Error in driver during machine creation: Too many retries waiting for SSH to be available. 
Last error: Maximum number of retries (60) exceeded


Run the following following steps:

1. Check your docker version:
$ docker -v
Docker version 18.03.0-ce, build 0520e24


2. Download your docker version's of `boot2docker` (18.03.0-ce) from here into your local:
wget https://github.com/boot2docker/boot2docker/releases/download/v18.03.0-ce/boot2docker.iso -P ~/.docker/machine/cache/test/boot2docker-v18-03-0-ce.iso


3. Create the `new_virtual_box_name` using the downloaded version of `boot2docker`:
docker-machine create --driver virtualbox --virtualbox-boot2docker-url ~/.docker/machine/cache/test/boot2docker-v18-03-0-ce.iso new_virtual_box_name


Tuesday, 13 November 2018

SAML Auth login issue on local - undefined logger()

(1/1) FatalThrowableError
Call to undefined function App\Http\Controllers\logger()

in SamlController.php line 85
at SamlController->acs()
at call_user_func_array(array(object(SamlController), 'acs'), array())
in BoundMethod.php line 29


Enable the Saml debugger by adding the `SAML2_DEBUG=true` on .env.

Then, found the following error:
openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate!
Whoops, looks like something went wrong.
(1/1) FatalThrowableError
Call to undefined function App\Http\Controllers\logger()

in SamlController.php line 87
at SamlController->acs()
at call_user_func_array(array(object(SamlController), 'acs'), array())
in BoundMethod.php line 29
at BoundMethod::Illuminate\Container\{closure}()
in BoundMethod.php line 87


Resolved the issue after updating with the correct `SAML2_IDP_X509CERT` value.

Friday, 25 May 2018

Angular production test locally with hostName, Port and SSL on

ng serve --prod --build-optimizer --ssl --host demo.yourdomain.local --port 4202

Thursday, 1 March 2018

Useful docker commands for cleaning up containers, images and volumes

List of useful docker commands for cleaning up containers, images and volumes:

docker stop $(docker ps -aq // Stop all containers
docker rm $(docker ps -aq) // Remove all containers
docker rmi $(docker images -q) // Remove all images
docker volume ls // List all volumes
docker volume ls -q -f dangling=true // List all dangling volumes
docker volume rm `docker volume ls -q -f dangling=true` // remove all dangling volumes

Friday, 16 February 2018

Add sticky content with jQuery

Steps:

1. Add the following on your css file.
.fixed-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 5;
}

2. Add the following on your JS file where you need to display the sticky when scrolling up.
jQuery(window).scroll(function(){
    if (jQuery(window).scrollTop() >= 200) {
        jQuery('.classNameOfStickyContentHere').addClass('fixed-header');
    }
    else {
        jQuery('.classNameOfStickyContentHere').removeClass('fixed-header');
    }
});

3. HTML Content
Display me as sticky when scrolling up....

Thursday, 19 October 2017

To create a custom token password reset in Laravel 5.5 (Or Lumen)

Please use the below passwordResetToken() function to get the token for password reset for custom use.

namespace App\Traits;

use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Password;

trait ResetPasswordTrait 
{
    ...
    ...
    ...
    ...

    /**
     * Get the token for password reset and update the token in the database table.
     *
     * @return string|null
     */
    public function passwordResetToken($user)
    {
        $this->broker = 'users';

        $broker = $this->getBroker();

        return Password::broker($broker)->createToken($user);
    }

    /**
     * Get the broker to be used during password reset.
     *
     * @return string|null
     */
    public function getBroker()
    {
        return property_exists($this, 'broker') ? $this->broker : null;
    }

}


// Reuse in the class
use App\Traits\ResetPasswordTrait;

class NewUserAccount 
{

    use ResetPasswordTrait;

    // Sample function to print the password reset token
    public function printPasswordResetToken(Request $request)
    {
        $user = User::find( $request->input('id') );
        $passwordResetToken = $this->passwordResetToken($user);
        print_r($passwordResetToken);
    }

}