
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
- How to use more than one query scope in Laravel
- How to check relationship is loaded or not in Laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Composer\Exception\NoSslException
- How to pass external link in laravel blade to anchor tag
- How to check record exist or not in relationship table
- Extract only time from datetime in laravel
- How to create pivot table in laravel using migration
- How to get query string value in laravel
- Conditional where clause in Laravel
- How to return error message from controller to view in laravel
- Conditional validation in laravel
- Property [user] does not exist on this collection instance
- Delete file from amazon s3 bucket using Laravel
- Redirect to another view from controller in laravel
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- Display data in table using foreach in Laravel
- How to insert dynamic value to additional column in pivot table in laravel
- Generate random string lowercase in Laravel
- Display option of select as selected with blade directive Laravel
- Call to a member function pluck() on null
- Attempt to read property "avatar" on null in Laravel
- Send id with route Laravel
- Laravel create multiple records in Pivot table
- How to upload multiple images after preview in laravel using cropper js