-
The devastating flood which is known as Himalayan Tsunami was occured in the year
-
Which city is also known as the "Yoga Capital of the World"
-
Total number of National Parks in Uttarakhand
-
What is the literacy rate of Uttarakhand according to 2011 census
-
Besides Hindi, which one is the other official language of Uttarakhand
-
Total number of districts in Uttarakhand
-
Who was the first Chief Minsiter of Uttarakhand
-
Which one is the highest mountain in Uttarakhand
-
Which river passed through the Valley of Flowers
-
In which district, the Jageshwar temple is located
-
The Char Dham Yatra begins every year in the month of
-
In which year Uttarakhand was established as a separate state
-
Which one is the largest district by area wise in Uttarakhand
-
At Dev Prayag, the Bhagirathi river meets with the
-
In which year, the Chipko Movement was awarded with the Right Livelihood Award
-
The Treaty of Sugauli took place in the year
-
According to 2011 census, which district of Uttarakhand had negative population growth rate
-
Which one is the largest glacier in Uttarakhand
-
The Uttarakhand High Court is located at
-
Which lake of Uttarakhand is also known as "mystery lake"
-
'Pinder River' joins Alaknanda at
-
Which one of the following is a biosphere reserve in Uttarakhand
-
Which Queen is also known as "Nakati Rani" in Garhwal
Uttarakhand Objective gk Question in English
Laravel Eloquent ORM Query and Model Feature
Laravel Eloquent feature is object Oriented paradigm approach of database communication. In Eloquent we create Model for each Table in the database, which set the communication (Fetching, Inserting, Deleting, Modifying the Record ) with database.
You can create the Model with Migration or without migration with the help of Artisan Command. We can use -m or --migration after the artisan command to create the Model with Migration. Below code is the Example.
Eloquent Model with Database Migration
Create Model with migration using Artisan Command. Below is the command to create Model with migration.
php artisan make:model model-Name -m (-m is for migration )
php artisan make:model model-Name --migration (--migration is for migration )
This above two Artisan Command will create Table migration file in your databaese / migration directory which you can modify further.
Create Model without Migration. Below is the Artisan command to create Model.
php artisan make:model model-Name
Lets Take Example, We will create Model Named with CategoryMaster
php artisan make:model CategoryMaster -m
This above Artisan Command will create the Model named with CategoryMaster. Below is the code for your reference
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class CategoryMaster extends Model
{ // }
namespace App;
use Illuminate\Database\Eloquent\Model;
class CategoryMaster extends Model
{ // }
Eloquent Model Property
In the above model, we didn't mention the table. So we have to declare the table in CategoryMaster Model.
protected $table = '"category_table";
In Eloquent Model, Eloquent consider by default each table has a primary key id with incrementing integer Value. How to Define a protected Primary key property:
protected $primaryKey = '"id";
protected $incrementing = '"false";
if Primary Key is not an integer then you must set the KeyType a string.
protected $keyType = 'string';
Once the Table is declared in the Model, By Default timestamp (Created_at, updated_at) will be true. If you don't want them then you have to set the timestamp to false.
protected $timeStamp = "false";
Eloquent Model and Database Connection
Eloquent model will use Default Database which got configured with your laravel Application. if you wish to have your model connected with other database then you have to use $connection Property. Code is below for your reference.
protected $connection = "Connection-Database-Name";
Fetch / Retrieve Model In Eloquent
Once the Model is Created with Associated table, We can perform all the database operation(CRUD) on it. We will Query / fetch database table associated with model step by step.Above we have created CategoryMaster Model, Now we will use this model for writing our Eloquent Query as a Example.
$data= App\CategoryMaster::all();
all() method in Eloquent will return all result from the specified model table. We can use various constraint on the all method to filter the table record.
$data = App\CategoryMaster::where('status', 1)->orderBy('id', 'desc') ->take(5)->get();
As Eloquent is Query Builder you can use all the Query Builder method for database Operation.
Subscribe to:
Posts (Atom)
Our Feature Post
There is a tree between houses of A and B If the tree leans on As House
There is a tree between houses of A and B. If the tree There is a tree between houses of A and B. If the tree leans on A’s House, the t...
Our Popular Post
-
👉 Reema can complete a piece of work in 12 days while Seema can the same work in 18 days. If they both work together, then how many da...
-
Probability Question and Solutions Two dice are thrown simultaneously. What is the probability of getting two numbers whose product...
-
The average of 11 numbers is 30. If the | Solutions The average of 11 numbers is 30 . If the average of first six numbers is...
-
Karan, Hari and Kowshik play cricket. The runs got by Karan to Hari and Hari to Kowshik are in the ratio of 5:3. They get altogether 588 ...
-
Analogies Questions :: Logical Reasoning 👉 Analogies shortcut tricks, Formula, Method and Notes 👉 Analogies Questions and a...