Categories

Saturday, July 20, 2024
#919814419350 therichposts@gmail.com
LaravelLaravel 5.8Uncategorized

Laravel select2 with json data working example

Hello to all, welcome to therichpost.com. In this post, I will tell you, Laravel select2 with json data working example.

laravel-select2
laravel-select2

Here is the complete working code and you can add this any of your’s laravel blade template file:

http://prntscr.com/ouhn27
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel</title>

        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
        <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/css/select2.min.css" rel="stylesheet" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js"></script>

        <!-- Custom Script -->
        <script>
        $(document).ready(function() {
            var sampleArray = [{id:'AL',text:'Alabama'}, {id:'WY',text:'Wyoming'}];
            $('.js-example-basic-single').select2({data: sampleArray});
        });
        </script>
    </head>
    <body>
    <div class="jumbotron text-center">
    <h1></h1>
    <p></p> 
    </div>
    <div class="container">
        <div class="row">
            <div class="col-sm-8">
            <select class="js-example-basic-single form-control" name="state">
                <option value="AL">Alabama</option>
                <option value="WY">Wyoming</option>
            </select>
            </div>
        </div>
    </div>
    </body>
</html>

If you have any query related to this post, then please let me know.

Jassa

Thank you

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.