laravel(part5-fetch data from db)
- sondip poul singh
- Jan 17, 2019
- 1 min read
create a new controller for displaying the name.make a new route and a public function in the controller like the previous ones.in the controller write
use App\model_name;
this says which model are we going to use for fetching data as we know models are responsible for each table.Now do the followings
class NamesController extends Controller { public function allname() { $name= info::all(); return view('names')->with('stu_names',$name); } }
here info is the model name and by all we are fetching all the data from db. As we are returning a view we are sending the data along it. In the view file the 'stu_names' variable will be used.
Finally in names view we write the following codes as displaying content:
@foreach($stu_names as $names) {{$names->name}} <br> @endforeach
Thats it.Awesome!!!
Comments