Creating tables in Migration

In Laravel to create a new database table first of all we need to make a migration which we have explained in the previous blog. I recommend you to read that blog, you can refer the link given below:


https://www.scmgalaxy.com/tutorials/explanation-of-database-migrations-in-laravel-5-8/

Once we are done with creating a migration file, to create a new database
table we have to use the create method on the Schema facade. The create method accepts two arguments:-

The first is the name of the table, while the second is a closure which receives a Blueprint object that may be used to define the new table:

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->string('email');
    $table->timestamps();
});

In the table we can add number of $table as per our requirement. There are several data type which we can use while creating the $table. Few of them are given below:

bigIncrements()

The bigIncrements method creates an auto-incrementing UNSIGNED BIGINT (primary key) equivalent column:

$table->bigIncrements('id');

bigInteger()

The bigInteger method creates a BIGINT equivalent column:

$table->bigInteger('votes');

id()

The id method is an alias of the bigIncrements method. By default, the method will create an id column; however, you may pass a column name if you would like to assign a different name to the column:

$table->id();

rememberToken()

The rememberToken method creates a nullable, VARCHAR(100) equivalent column that is intended to store the current “remember me” authentication token:

$table->rememberToken();

string()

The string method creates a VARCHAR equivalent column of the given length:

$table->string('name', 100);

text()

The text method creates a TEXT equivalent column:

$table->text('description');

To know more about creating tables and adding columns, you can refer the video given below:

Tagged : / / /

Explanation of Database Migrations in Laravel 5.8

Migration is a way that allows us to create a table in our database, without accessing the database manager such as phpmyadmin or sql lite.

To create a migration we should execute the command:

php artisan make:migration [options] [--] <name>

Here, in the option we have number options to enter depending upon the requirement. We can see all the options given below:

–create[=CREATE]The table to be created
–table[=TABLE] The table to migrate
–path[=PATH] The location where the migration file should be created
–realpath Indicate any provided migration file paths are pre-resolved absolute paths
–fullpath Output the full path of the migration
-h, –help Display this help message
-q, –quiet Do not output any message
-V, –version Display this application version
–ansi Force ANSI output
–no-ansi Disable ANSI output
-n, –no-interaction Do not ask any interactive question
–env[=ENV] The environment the command should run under
-v|vv|vvv, –verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Once we create the migration we can see a file under Migration-> database. Migrations are files which contain a class definition with both an up() and a down() method. The up() method helps to apply changes to the database and the down() method is used to rollback the changes in the database.

Example:-

class CreateCustomersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('customers', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('customers');
    }
}

To run all of our outstanding migrations, we can execute the Artisan command given below:

php artisan migrate

Also once we execute our migrations in the database we do have the option to roll back the latest migration operation, by using the rollback Artisan command. This command rolls back the last “batch” of migrations, which may include multiple migration files:

php artisan migrate:rollback

In Laravel we also have an option to rollback and execute the migration simultaneously with an Artisan command:

php artisan migrate:refresh

To see a video for the topic you can follow the video given below:-

Follow the other blog in which we will learn about creating tables in the database.

Tagged : / /

Bootstrap Tutorial

INTRODUCTION:-

Bootstrap is framework of HTML,CSS and JavaScript for developing responsive websites. It is free to use and download. It is front end framework which makes web development faster and easier. It have many HTML and CSS based templates for  forms,buttons,tables etc.

HISTORY:-

Bootstrap was developed by Mark Otto and Jacob Thorton. It was first released as an open source in August 2011.

ADVANTAGES:-

  1. Bootstrap is very easy to use.
  2. Anyone who have basic knowledge of HTML and CSS can use it very easily.
  3. It help users to develop responsive websites very easily.
  4. Bootstrap is compatible on most of the browser.

BOOTSTRAP CONTAINER:-

The container class is used to create boxed content.

Example:-

  1.         <html>  
  2.  <body>  
  3.   <div class=“container”>  
  4.    <div class=“row”>  
  5.      <div class=“col-md-xx”></div>  
  6.        …  
  7.    </div>  
  8.    <div class=“row”>  
  9.      <div class=“col-md-xx”></div>  
  10.        …  
  11.    </div>  
  12.   </div>  
  13.  </body>  
  14. </html>  

BOOTSTRAP JUMBTRON:-

The jumptron is used to specify big box for getting extra attention. It is a box with rounded corner. It is used in <div>.

Example:-

  1. <!DOCTYPE html>  
  2. <html lang=“en”>  
  3. <head>  
  4.   <title>Bootstrap Example</title>  
  5.   <meta charset=“utf-8”>  
  6.   <meta name=“viewport” content=“width=device-width, initial-scale=1”>  
  7.   <link rel=“stylesheet” href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css”>  
  8. </head>  
  9. <body>  
  10.   
  11. <div class=“container”>  
  12.   <div class=“jumbotron”>  
  13.     <h1>This is Jumbotron inside container!</h1>        
  14.     <p>Jumbotron specifies a big box for getting extra attention to some special content or information.</p>  
  15.   </div>  
  16.   <p>This is some text.</p>        
  17.   <p>This is another text.</p>        
  18. </div>  
  19.   
  20.   <script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js”></script>  
  21.   <script src=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js”></script>  
  22. </body>  
  23. </html>

BOOTSTRAP BUTTONS:-

There are 7 buttons present in boot strap:

  1. .btn-primary
  2. .btn-default
  3. .btn-info
  4. .btn-danger
  5. .btn-link
  6. .btn-warning
  7. .success  

Example:-

  1. <!DOCTYPE html>  
  2. <html lang=“en”>  
  3.   <head>  
  4.      <title>Job</title>  
  5.      <link rel=“stylesheet” href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css”/>  
  6.   </head>  
  7.   <body>  
  8.     <h1>Button Example!</h1>  
  9.   
  10. <button class=“btn btn-default”>default</button>  
  11. <button class=“btn btn-primary”>primary</button>  
  12. <button class=“btn btn-danger”>danger</button>  
  13. <button class=“btn btn-success”>success</button>  
  14. <button class=“btn btn-info”>info</button>  
  15. <button class=“btn btn-warning”>warning</button>  
  16. <button class=“btn btn-link”>Link</button>  
  17.   
  18. <script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js”></script>
  19.   <script src=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js”></script>  
  20.   </body>  
  21. </html>  

Classes for button size:-

  1. .btn-lg
  2. .btn-md
  3. .btn-sm
  4. .btn-xs

BOOTSTRAP TABLES:-

We can use bootstrap to design different types or table.

Example:-

  1. <!DOCTYPE html>  
  2. <html lang=“en”>  
  3.   <head>  
  4.      <title>Job</title>  
  5.      <link rel=“stylesheet” href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css”/>  
  6.   </head>  
  7.   <body>  
  8.   
  9. <div class=“container”>  
  10.   <h1>Basic Table Example</h1>  
  11.   
  12. <table class=“table”>  
  13.   <tr><th>Id</th><th>Name</th><th>Age</th></tr>  
  14.   <tr><td>101</td><td>Rahul</td><td>23</td></tr>  
  15.   <tr><td>102</td><td>Umesh</td><td>22</td></tr>  
  16.   <tr><td>103</td><td>Max</td><td>29</td></tr>  
  17.   <tr><td>104</td><td>Ajeet</td><td>21</td></tr>  
  18. </table>  
  19.   
  20. </div>  
  21.   
  22. <script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js”></script>  
  23.   <script src=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js”></script>  
  24.   </body>  
  25. </html>  
  • <tr> is used for table row.
  • <td> is used for table data.
  • <th> is used for table heading.

BOOTSTRAP FORMS:-

There are three types of forms in bootstrap.

  1. Horizontal form
  2. Vertical form
  3. Inline form

Example 1( vertical form):-

  1. <!DOCTYPE html>  
  2. <html lang=“en”>  
  3.   <head>  
  4.      <title>Bootstrap example</title>  
  5.      <link rel=“stylesheet” href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css”/>  
  6.   </head>  
  7.   <body>  
  8.   
  9. <div class=“container”>  
  10.   <h1>Vertical Form Example</h1>  
  11.   
  12. <form style=“width:300px”>  
  13.   <div class=“form-group”>  
  14.     <label for=“exampleInputEmail1”>Email address</label>  
  15.     <input type=“email” class=“form-control” id=“exampleInputEmail1” placeholder=“Email”>  
  16.   </div>  
  17.   <div class=“form-group”>  
  18.     <label for=“exampleInputPassword1”>Password</label>  
  19.     <input type=“password” class=“form-control” id=“exampleInputPassword1” placeholder=“Password”>  
  20.   </div>  
  21.     
  22.   <button type=“submit” class=“btn btn-default”>Login</button>  
  23. </form>  
  24.   
  25. </div>  
  26.   
  27. <script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js”></script>  
  28.   <script src=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js”></script>  
  29.   </body>  
  30. </html>  

Horizontal form:-

  1. <!DOCTYPE html>  
  2. <html lang=“en”>  
  3. <head>  
  4.   <title>Bootstrap Example</title>  
  5.   <meta charset=“utf-8”>  
  6.   <meta name=“viewport” content=“width=device-width, initial-scale=1”>  
  7.   <link rel=“stylesheet” href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css”>  
  8.     
  9. </head>  
  10. <body>  
  11.   
  12. <div class=“container”>  
  13.   <h2>Horizontal form Example</h2>  
  14.   <form class=“form-horizontal” role=“form”>  
  15.     <form style=“width:300px”>  
  16.   <div class=“form-group”>  
  17.       <label class=“control-label col-sm-2” for=“email”>Email:</label>  
  18.       <div class=“col-sm-10”>  
  19.         <input type=“email” class=“form-control” id=“email” placeholder=“Enter email”>  
  20.       </div>  
  21.     </div>  
  22.     <div class=“form-group”>  
  23.       <label class=“control-label col-sm-2” for=“pwd”>Password:</label>  
  24.       <div class=“col-sm-10”>            
  25.         <input type=“password” class=“form-control” id=“pwd” placeholder=“Enter password”>  
  26.       </div>  
  27.     </div>  
  28.     
  29.   <div class=“form-group”>          
  30.       <div class=“col-sm-offset-2 col-sm-10”>  
  31.         <button type=“submit” class=“btn btn-default”>Submit</button>  
  32.       </div>  
  33.     </div>  
  34.   </form>  
  35. </div>  
  36. <script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js”></script>  
  37. <script src=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js”></script>  
  38.   
  39. </body>  
  40. </html>  

Inline form:-

  1. <!DOCTYPE html>  
  2. <html lang=“en”>  
  3. <head>  
  4.   <title>Bootstrap Example</title>  
  5.   <meta charset=“utf-8”>  
  6.   <meta name=“viewport” content=“width=device-width, initial-scale=1”>  
  7.   <link rel=“stylesheet” href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css”>  
  8.     
  9. </head>  
  10. <body>  
  11.   
  12. <div class=“container”>  
  13.   <h2>Inline form Example</h2>  
  14.   <form class=“form-inline” role=“form”>  
  15.     <form style=“width:300px”>  
  16.   <div class=“form-group”>  
  17.     <label for=“exampleInputEmail1”>Email address</label>  
  18.     <input type=“email” class=“form-control” id=“exampleInputEmail1” placeholder=“Email”>  
  19.   </div>  
  20.   <div class=“form-group”>  
  21.     <label for=“exampleInputPassword1”>Password</label>  
  22.     <input type=“password” class=“form-control” id=“exampleInputPassword1” placeholder=“Password”>  
  23.   </div>  
  24.     
  25.   <button type=“submit” class=“btn btn-default”>Login</button>  
  26. </form>  
  27.   
  28. </div>  
  29. <script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js”></script>  
  30.   <script src=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js”></script>  
  31.   
  32. </body>  
  33. </html>  

How Control flow in Laravel

Route::get(‘task’,’TaskController@index’)->name(‘task’); Explanation:- name(‘task‘) is given in the URL as http://127.0.0.1:8000/task. Control flow:- As the URL is hit the control will go the route(web.php), there it will get Route::get(‘task’,’TaskController@index’)->name(‘task’); Here, there will be a name match from the URL and if there is match then there will be a function call named index and route will redirect to TaskController.php where it will find the function index and operate according to the instructions given inside it.

After the create operation we need to store the data in the database for this we used <form action=”{{route(‘store’)}}” method=”POST”> which will call store function. The store function be like

The in store function we create object $var of Task class make variables as $var->task which is assigned $request->task; (gets value from 1st field) & $var->detail which is assigned $request->detail; (gets value from 2nd field) and $var->save(); function will save it to the database.

Tagged : / / /