Giter Site home page Giter Site logo

laravel-dependent-select-box's Introduction

laravel-dependent-select-box

This is a simple Dependent Select Box with Ajax and Laravel (I assume you have a project up and running)

Create a Database: Select (I used PHPMYADMIN - MYSQL)

now navigate to laravel project on command prompt and type:

php artisan make:migration create_country_state_tables

After this command you will find one file in following path database/migrations and you have to put the below code in your migration file for create tables.

public function up() { Schema::create('country', function(Blueprint $table){ $table->increments('id'); $table->string('name'); $table->timestamps(); });

    Schema::create('state', function(Blueprint $table){

        $table->increments('id');
        $table->integer('country_id');
        $table->string('name');
        $table->timestamps();
    });
}


Now on command prompt type: php artisan migrate

Now go to phpmyadmin, Insert ID, and Country (1, Nigeria)

Then for state(Insert state id,  country id and state name) do something like this: INSERT INTO `state` (`id`, `country_id`, `name`, `created_at`, `updated_at`) VALUES ('1', '1', 'Lagos', '2017-04-10 08:16:44', '2017-09-19 13:18:28'), ('2', '1', 'Delta', '2017-06-14 08:14:27', '2017-06-07 07:40:12');

This is my Route Configuration for this project:

Route::get('/', 'HomeController@index');
Route::get('states/get/{id}', 'HomeController@getStates');

THe ajax calls are located externally at (public\js\custom.js)

This should get you up and running.

Hey Ya!

laravel-dependent-select-box's People

Contributors

emmanueladegor avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.