laravel get data from database code example

Example 1: how to get data from a table in laravel

use Illuminate\Support\Facades\DB;

class UserController extends Controller
{
    public function index()
    {
        $users = DB::table('users')->select('id','name','email')->get();

        return view('some-view')->with('users', $users);
    }
}

Example 2: get database name laravel

DB::getDatabaseName();

Example 3: How to request and display data from db in larave

$users = DB::table('users')->get();
foreach($users as $key => $value)
{
	//to get each columns value
	//$value->name
}

Example 4: DB::table('users')->get();

DB::table('users')->where('name', Input::get('name'))->get();

Example 5: laravel get data from request

dd($request->all());
//print an array of the input name and the input value

Tags:

Php Example