Laravel - Getting Started - Running A Select Query

To run a basic SELECT query, you may use the select method on the DB facade:

    
     $users]);
        }
    }
	

The first argument passed to the select method is the SQL query, while the second argument is any parameter bindings that need to be bound to the query. Typically, these are the values of the where clause constraints. Parameter binding provides protection against SQL injection.

The select method will always return an array of results. Each result within the array will be a PHP stdClass object representing a record from the database:

    
    use Illuminate\Support\Facades\DB;
    
    $users = DB::select('select * from users');
    
    foreach ($users as $user) {
        echo $user->name;
    }