Friday, June 24, 2016

Angular 2 Beginning using Component

Angular 2 Beginning using Component:

In beginning, open app.component.ts file and write the code in it.

import {Component} from 'angular2/core';

@Component({
    selector: 'my-app',
    template: `        <h1 (click)="onSelect()">Ashish Ginotra's</h1>        <p>Hello World!</p>        <h1 *ngIf="showDetail === true">This is {{contact.lastname}}</h1>        <input [(ngModel)]="contact.lastname" type="text">    `,
})
export class AppComponent {
    public contact = {firstname:"Ashish",lastname:"Ginotra"};
        public showDetail = false;
    onSelect(){
        this.showDetail = true;
    }
}

Add this code in your file and run

npm strat.

This will show the output.

Thanks

Friday, June 17, 2016

Token Mismatch error on login page Laravel 5

Token Mismatch error on login page Laravel 5:

Sometimes we noticed on the login page of Laravel 5, when we leave this page for sometimes and then click on login button, then it shows token mismatch error.

This is because session time of laravel has been expired and current token for that page do not match the actual page.

For prevent this kind of error, we have to handle it.

Goto this file :  app/Exceptions/Handler.php

and add this code in render function.

    public function render($request, Exception $e)
    {
        if ($e instanceof \Illuminate\Session\TokenMismatchException) {
            return redirect()->guest('auth/login');
        }
        return parent::render($request, $e);
    }


Thanks

Friday, June 10, 2016

Resize image in Laravel 5

Resize image in Laravel 5:

For resizing image in laravel:

Firstly we have to install a package. For this open your composer.json and write this code in require.

"intervention/image": "dev-master"

then run composer update

In config/app.php write this code in aliases

'Image'     => Intervention\Image\Facades\Image::class,

and this in providers

Intervention\Image\ImageServiceProvider::class,

Now go to your controller & use this.

use Intervention\Image\Facades\Image;

 Now go to your method and write this code

$dirName = 'path/of/image';
$img = Image::make($dirName . "/background.jpg")->resize(720, 1280);
$img->save($dirName . "/background.jpg");


Thanks

Friday, June 3, 2016

How to delete latest file in folder in php

How to delete latest file in folder in php:

For delete the latest file in php we have to use following code.

           $filePath = 'path/of/folder';
            $files = glob($filePath . '/*.*');
            array_multisort(
                array_map('filemtime', $files),
                SORT_NUMERIC,
                SORT_ASC,
                $files
            );
            exec("rm -rf " . $files[0]);


Thanks