
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
- Laravel form request validation
- How to upload multiple images after preview in laravel using cropper js
- Insert values in pivot table dynamically in laravel
- How to get id of next record in laravel
- How to add foreign key in laravel using migration
- Calculate age from date of birth in Laravel
- Delete file from amazon s3 bucket using Laravel
- How to fetch single row data from database in laravel
- Redirect from www to non www in laravel using htaccess
- Define variable and use in Laravel controller method
- How to validate form input data in laravel
- Get current URL on visit URL in Laravel
- How to check duplicate entry in laravel
- How to get images from AWS s3 and display in Laravel blade
- How to create projects method with belongstomany relationship in user model
- How to check column value of a record is null or not in laravel
- Split an Eloquent Collection by half in Laravel
- Comment .env file in laravel
- How to validate website url in laravel using validaiton
- Undefined property: stdClass::$title
- Display message with session flash using bootstrap alert class in laravel
- How to include header file in laravel
- Laravel csrf token mismatch for ajax POST Request
- If condition in Laravel 9
- Count all and get 10 records after where condition in laravel