Laravel is the PHP Web development Framework (PHP Web framework). It frees you from messy code, it helps you build a perfect web app, and every line of code can be concise and expressive. So, how does the Laravel framework operate the database?
Recent small series in learning the world's most bull frame –laravel. In fact, learning framework is the idea of learning the framework! I would like to record in my blog Some of my experience in the Laravel study, Welcome to my other GitHub blog
There are two ways to perform database operations in Laravel. one is to use the static method of the \ DB appearance object to directly execute SQL queries, another method is to use the static method of the Model class (in fact, it is also the
One, selects retrieve all rows in the table
$users = db::table (' users ')->get ();
foreach ($users as $user)
{
var_dump ($user->name);
}
retrieving a single row from a table
$user = db::table (' users ')->where (' name ', ' John ')->first
Laravel Database BasicsLaravel making it easy to connect to the database and run the query. The application's database configuration is located inconfig/database.php . In this file you can define all the database connections and specify which
Laravel is a simple, elegant frame that can be said to be the second choice after the introduction TP.Catalog section:
Code written by App--
Controller, HTTP
Bootstrap-Frame self-loading files
Config--config file
The above code can be executed, but all the fields in the attribute of the associated model are still queried.
$ User = UserAttribute: where ('uid', $ uid)-> with (['attribute' => function ($ query) {$ query-> pluck ('title') ;},])-> get ();
The
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.