@lizzie
To run a MySQL query in Laravel, you can use Laravel's built-in Eloquent ORM or the Query Builder. Here's how you can run a MySQL query using the Query Builder:
1 2 3 |
use IlluminateSupportFacadesDB; $results = DB::select('SELECT * FROM users'); |
1 2 3 4 5 |
$users = DB::table('users') ->select('name', 'email') ->where('status', 'active') ->orderBy('created_at', 'desc') ->get(); |
1 2 3 4 5 |
DB::table('users')->insert([ 'name' => 'John Doe', 'email' => '[email protected]', 'password' => bcrypt('secret'), ]); |
These are some basic examples of how to run MySQL queries in Laravel using the Query Builder. The Eloquent ORM provides an easier and more convenient way to interact with your database, so you may want to explore that option as well.