Laravel eloquent

Laravel is an MVC based PHP framework. In MVC architecture, ‘M’ stands for ‘Model’. A Model is basically a way for querying data to and from the table in the database. Laravel provides a simple way to do that using Eloquent ORM (Object-Relational Mapping). Every table has a Model to interact with the table.

Model:

class Flight extends Model
{
   protected $table='my_flights';
}
Controller:

use App\Models\Flight;

$flights = Flight::where('active', 1)
->orderBy('name')
->take(10)
->get();

 

Leave a Reply