Database: Query Builder

In this we will learn how to use database query in the controller. First of all we need to import database class by mentioning:

use DB;

By importing DB class we can execute data through controller. Now we need to make a function in the controller and insert the values.

Then in the blade view we need to call the values:

Now we can serve the local server php artisan serve and we can see the details provided in the database.

You can see the demonstration in the video given below:

Php Artisan Tinker in Laravel

Tinker command is used to create a connectivity with the database as it allows us to create the objects, insert the data, etc in the database.

To run the tinker command we should execute:

php artisan tinker

To run the tinker command first of all we need to create table in the database through migration command which we have explained in the previous blog. Please refer that for creating tables.

Once we provide the details in the given table we can migrate it to the database by using php artisan migrate command and we can see the columns in our local database.

After migrating we can run the tinker command and insert data in the table using tinker:

php artisan tinker

-Single Row Insertion

-Multi Row Insertion

These commands will insert the data in the database and you can view these details by running the command given below:

To find a particular value from the database run the following command:

To find a particular column from the database run the following command:

Some of the fetch commands of tinker are given below:

To update any value in the table we can follow the command given below:

To delete any value in the table we can follow the command given below:

To delete the entire table we can follow the command given below:

So there are the commands used in tinker, you can also see the detailed video which is given below:

Tagged : /