How to use DB Laravel ?
How to use DB Laravel ?
In this session, we are going to try to solve the "How to use DB Laravel ?" puzzle by using the computer language.
You can use `DB::select('select * from users');` query after importing the `use Illuminate\Support\Facades\DB;` in class after namespace.-
app\Http\Controllers\<HomeController>.php
Import DB facade after namespace (
namespace App\Http\Controllers;
) and before class definition (class HomeController extends Controller
) in HomeController class.use Illuminate\Support\Facades\DB;
Code in controller method
$users = DB::select('select * from users'); return view('home', compact('users'));
resources\views\home.blade.php
@foreach ($users as $user) <p>This is user {{ $user->id }}</p> @endforeach
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Ajax POST request in laravel
- Get comma separated email from input array
- Get products with number of orders in Laravel
- How to start websocket server in laravel
- Post table seeder laravel 10
- How to get last year records count with month wise in Laravel
- How to authenticate admin users in Laravel ?
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- On delete set foreign id column value null using migration in laravel 8
- How to insert ckeditor data into database in Laravel?
- How to pass query string to url in laravel
- The openssl extension is required for SSL/TLS protection but is not available
- How to get column names from table in Laravel
- Display first n record from collection in laravel view
- Call to undefined method App\Models\User::follow()
- How to check find method executed successfully in laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- Laravel create multiple records in Pivot table
- How to fill a column automatically while creating records in Laravel
- Remove public from url in laravel project
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- Insert current date time in a column using Laravel
- How to remove P tag from CkEditor in Laravel?
- Get latest record by created at in Laravel
- If no route matched route::fallback in laravel