Laravel 5 Tutorial (05) :: Retrieve data from database table.

From Last tutorial we learnt how to insert data in our database table. Today I’ll discuss about how to retrieve data from our database. Let’s see the procedure.

You can read previous posts

Go to TodoController and define the index method like as below

public function index()
  return view('home')->with('data',$data);

Explain : Here Todo is our model name and all is a method of  laravel eloquent class. By this all method we get all record from our todo table. Here we don’t have to write any sql query like select * from todo. Laravel eloquent class will automatically make query for us. Here we store all the record in data variable and finally send the data variable by with method in our view (home.blade.php).

Now open the home.blade.php file from resources/views folder and add the codes after 1st tr of table.

@foreach($data as $row)
            <a href="#">Complete</a> | <a href="#">Edit</a> | <a href="#">Delete</a>

Explain : Here data variable is which we sent from our TodoController‘s index method. We make 3 links for our next operations Complete,Edit and delete.

Complete : This link for mark as completed the task.
Edit : This link for edit task.
Delete : This link for delete the task record.

Now browse the http://localhost/todo/public , you will see all record from our todo table like as below



In next tutorial I’ll discuss about the edit procedure.

Share on :

Leave a Reply

− 5 = one