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
- First and last item of the array using foreach iteration in laravel blade
- If no route matched route::fallback in laravel
- InRandomOrder() method with example in laravel
- How to get last record from object collection in laravel
- How to display user profile after login in laravel
- Route [password.request] not defined
- Class App\Http\Controllers\Admin\UserController Does Not Exist
- Trying to get property 'title' of non-object
- How to update record after save method in Laravel
- Extra Filter Query on Relationships in Laravel
- How to get data from two tables in laravel
- How to add active class to menu item in laravel
- Get duplicate records in laravel
- How to validate URL with https using regex in laravel
- Page loader in laravel
- The use statement with non-compound name 'Auth' has no effect
- How to get only time from created_at in laravel
- Get content from web URL in laravel
- Redirect to previous page or url in laravel
- How to get random string in Laravel
- How to get specific columns using with method in laravel Eloquent relationship
- Property [user] does not exist on this collection instance
- How to check email is valid or not in Laravel
- FirstOrCreate() Not Inserting Model
- How to add a key value pair to existing array in laravel