laravel get table 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: DB::table('users')->get(); id 1
$users = DB::table('users')where('id','=', $userid)->get();
Example 3: laravel where
$users = DB::table('users')
->whereMonth('created_at', '12')
->get();
Example 4: laravel where
$users = DB::table('users')
->whereDate('created_at', '2016-12-31')
->get();
Example 5: laravel find query
foreach (Flight::where('foo', 'bar')->cursor() as $flight) {
//
}