Update, Insert, Delete and Display data from database with Laravel

Hi guys! In this tutorial I will speak again about the Laravel Framework. I will explain to you how you can easily insert, update and display data from database in a Laravel project.

To create this tutorial, I will follow the documention of Laravel: http://laravel.com/docs/4.2/queries

First I want to explain how to display data from database in Laravel.

Open your Controller, and in your action add this code:

$data = DB::table('data')->where('id','3')->first();
return View::make('hello',['data'=>$data->info]);

  • table('data') is the name of my table.
  • where('id','3') will extract data where id = 3.
  • 'hello' is the name of my view file where I want to display the data.
  • ['data'=>$data->info] will display the information from my table.

Now, you must add this code in your view file:

{{ $data }}

This variable will display the data from ['data'=>$data->info].

If you want to insert data in your database, use this code:

array('info' => 'Some information')

To update data, you can use this code:

->where('id', 1)
->update(array('info' => 'some informations'));

To delete, use this code:


Video tutorial:

Leave a Comment