Vue Js Toggle Switch Button Example

Hi Dev,

In this example, I will explain you how to use toggle switch button in vue js. wr will show example of toggle switch button in vue js.we will use vue-js-toggle-button npm package for bootstrap toggle button example. vue cli toggle button is a simple, pretty and customizable.

vue-js-toggle-button provide way to change label and make it default checked. you can also customize several option like value, sync, speed, color, disabled, cssColor, labels, switchColor, width, height, name and with change event.

below i will give you simple example from starch so, you can see full example use it in your app.

Step 1: Create Vue JS App

Now this step, we need to create vue cli app using bellow command:

vue create myAppSwitch
Step 2: Install vue-js-toggle-button package

below we need to install vue-js-toggle-button npm package for toggle switch.

npm install vue-js-toggle-button --save
Step 3: Use vue-js-toggle-button

In this step, We need to use vue-js-toggle-button package in main.js file of vue js app.

src/main.js
import Vue from 'vue'
import App from './App.vue'
import ToggleButton from 'vue-js-toggle-button'
  
Vue.config.productionTip = false
Vue.use(ToggleButton)
  
new Vue({
  render: h => h(App),
}).$mount('#app')
Step 4: Update App.vue File

Now this step, we need to update app.vue file, because i updated component so.

src/App.vue
<template>
  <div id="app">
    <Example></Example>
  </div>
</template>
  
<script>
import Example from './components/Example.vue'
   
export default {
  name: 'app',
  components: {
    Example
  }
}
</script>
Step 5: Create Example Component

Here, we will create Example.vue component with following

code. src/components/Example.vue
<template>
  <div class="container" style="text-align:center">
    <div class="large-12 medium-12 small-12 cell">
      <h1 style="font-family:ubuntu">Vue js toggle button example - Nicesnippets.com</h1>
  
        <toggle-button @change="onChangeEventHandler" :labels="{checked: 'On', unchecked: 'Off'}" style="margin-left: 20px" />
  
        <toggle-button :labels="{checked: 'Itsolutionstuff.com', unchecked: 'HDTuto.com'}" width="150" style="margin-left: 20px" />
  
        <toggle-button :labels="{checked: 'Yes', unchecked: 'No'}" style="margin-left: 20px" />
  
    </div>
  </div>
</template>
  
<script>
    
  export default {
    data(){
      return {
        file: ''
      }
    },
  
    methods: {
      onChangeEventHandler(){
          alert('hi');
      }
    }
  }
</script>

Now you can run vue app by using following command:

npm run serve

It will help you....

Laravel Validation Image Example

example for simply image validation in laravel

Hi Guys,

Today, I will learn you to create validation image in laravel.we will show example of laravel validation image.The file under validation must be an image (jpg, jpeg, png, bmp, gif, svg, or webp).

Here, I will give you full example for simply image validation in laravel bellow.

solution
$request->validate([
   'file' => 'image'
]);
Route : routes/web.php
Route::get('form/create','FromController@index');
Route::post('form/store','FromController@store')->name('form.store');
Controller : app/Http/Controllers/BlogController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Blade;
use App\Models\User;
use App\Models\Post;

class FromController extends Controller
{   
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function create()
    {
        return view('form');
    }
    
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function store(Request $request)
    {
        $request->validate([
           'file' => 'image'
        ]);
      dd('done');
    }
}
View : resources/views/form.php
<!DOCTYPE html>
<html>
<head>
  <title>From</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha512-MoRNloxbStBcD8z3M/2BmnT+rg4IsMxPkXaGh2zD6LGNNFE80W3onsAhRcMAMrSoyWL9xD7Ert0men7vR8LUZg==" crossorigin="anonymous" />
  <scrbooleant src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></scrbooleant>
  <scrbooleant src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></scrbooleant>
</head>
<body class="bg-dark">
  <div class="container">
    <div class="row">
      <div class="col-md-6 offset-3">
        <div class="card mt-5">
          <div class="card-header">
            <div class="row">
              <div class="col-md-9">
                Laravel Validation Image Example
              </div>
              <div class="col-md-3 text-right">
                <a href="{{ route('form') }}" class="btn btn-sm btn-outline-primary">Back</a>
              </div>
            </div>
          </div>
          <div class="card-body">
            @if (count($errors) > 0)
                  <div class="row">
                      <div class="col-md-12">
                          <div class="alert alert-danger alert-dismissible">
                              <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                              @foreach($errors->all() as $error)
                              {{ $error }} <br>
                              @endforeach      
                          </div>
                      </div>
                  </div>
                @endif
              <form action="{{ route('from.store') }}" method="post">
                @csrf
                <div class="row">
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Image:</label>
                      <input name="file" type="file" class="form-control">
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-12">
                    <button class="btn btn-block btn-success">Submit</button>
                  </div>
                </div>
              </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

It will help you...

Laravel Convert PDF to Image Example

convert pdf to image laravel

Hi Guys,

Today,I will learn you how to convert pdf to image in laravel. we will Pdf To Image Convert using imagick package. you can easyliy convert pdf to image any formate in laravel. if you want to convert pdf to image than you can use here example. we will show setp by step example laravel pdf to image convert.

Here, I will give you full example for pdf to image convert in laravel as below.

Step 1: Install Laravel

we are going from scratch, So we require to get fresh Laravel application using bellow command, So open your terminal OR command prompt and run bellow command:

composer create-project --prefer-dist laravel/laravel blog
Step 2: Installing Imagick PHP Extension And Configuration

Here In this step, I will install the Imagick PHP extension is available from the Ubuntu’s repositories. Like ImageMagick, to do an imagick php install we can simply run the apt install command.

sudo apt install php-imagick

If you require a previous version of php-imagick, you can list the version available from the Ubuntu repositories using the apt list command. This would be useful in the event that the latest patch introduces regressions, which is fairly uncommon.

sudo apt list php-magick -a

The -a flag tells apt to list all version of a package available from the repositories. The output will look similar to the following, and at the time of this writing, there was only a single version available.

php-imagick/bionic,now 3.4.3~rc2-2ubuntu4 amd64 [installed]
restart apache web server

Installing the module alone isn’t enough. In order for any new PHP extension to be used with your web application Apache must be restarted.

sudo systemctl restart apache2
Verify Installation

To verify the installation was successful and that the module is enabled properly, we can use php -m from the command line, and grep the results to limit the output to only the line that is important.

Run the following command to verify the installation.

 php -m | grep imagick

If the installation was successful, the output of the command will simply show one line, and it will only contain the name of the module imagick.

imagick

For a much more detailed verification of whether the PHP module was installed correctly, use the phpinfo() method.

From the command line, run the following command

php -r 'phpinfo();' | grep imagick

Which will output the following information, where the modules status is shown as enabled.

/etc/php/7.3/cli/conf.d/20-imagick.ini,
imagick
imagick module => enabled
imagick module version => 3.4.4
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.set_single_thread => 1 => 1
imagick.shutdown_sleep_count => 10 => 10
imagick.skip_version_check => 1 => 1

Alternatively, by adding the phpinfo() function to a php script, and then accessing the script from a web browser, we are able to see the module is installed and enabled.

After some authorization change in fowling the path

/etc/ImageMagick-6/policy.xml
 < policy domain="coder" rights="none" pattern="PDF" / >
To Convert
 < policy domain="coder" rights="read|write" pattern="PDF" / >
Step 3: Create Route

Now, we need to add resource route for pdf to image convert in laravel application. so open your "routes/web.php" file and add following route.

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FromController;

Route::get('form', [FromController::class, 'index'])->name('form');
Step 3: Create Controller here this step now we should create new controller as FromController,So run bellow command for generate new controller
php artisan make:controller FromController
At last step we need to update FromController.php.
<?php

namespace App\Http\Controllers;

use Imagick;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Blade;

class FromController extends Controller
{   
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $imagick = new Imagick();

        $imagick->readImage(public_path('dummy.pdf'));

        $imagick->writeImages('converted.jpg', true);

        dd("done");
    }
}

Now we are ready to run our custom validation rules example so run bellow command for quick run:

php artisan serve

Now you can open bellow URL on your browser:

http://localhost:8000/form

It will help you....