DISPLAY MYSQL DATABASE TABLE DATA TO A VIEW/BLADE USING MODEL AND A CONTROLLER (P1)

Опубликовано: 21 Май 2026
на канале: Leo Paliuanan
305
3

Topic: how to display mysql database table data to a view/blade using a model and a controller (Part 1)

Important notes to consider:
1. make sure to watch and complete the following video tutorials before going to the process of this video...


   • CREATE ROUTE WITH CONTROLLER THAT REDIRECT...  
CREATE ROUTE WITH CONTROLLER THAT REDIRECTS TO A VIEW OR WEBPAGE (P1)


Steps:
1 open xampp - start apache and mysql
2 open vscode - open current laravel project installed/created


we are going to display the content of our database table = product into this webpage or blade.

using a model and a controller on the process

Controller : ProductsCtrl.php
Model : products.php


3 open controller and look for public function index();
add the following codes:

use App\Models\products;
this code must be added before the main class inside the controller

$prods = products::all();
this code must be added inside public function index




4 add - with('prods',$prods);

add this line after the return view




5 goto the resources - views and open the view/blade file
add the following codes:

@foreach($prods as $prod)

@endforeach


add the line outside the tag li




6 inside the tag li

change the content with {{$prod- productname}}


{{$prod- productname}} {{$prod- description}} {{$prod- price}} {{$prod- stock}}

lets check field names on our table products just to be sure
open localhost/phpmyadmin using a browser

{{$prod- productname}} {{$prod- description}} {{$prod- price}} {{$prod- stock}}

add the following codes put it inside the tag li


7 Lets add data into our database table products to see the actual data being displayed into our view or webpage

go back to localhost/phpmyadmin
click insert tab and add new set of sample data



8 go back to the browser into our project and refresh
lets add again



// this line will get all the data inside the table products
$prods = products::all();

// return will redirect the user webpage into our webpage or blade file
// with method will pass the data to our blade or webpage
return view('Products')
with('prods',$prods);