Friday 1 February 2019

Laravel Model

https://laravel.com/docs/5.7/eloquent

    Laravel Model located in app/Http/Controllers/


    Introduction

    The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.
    Before getting started, be sure to configure a database connection in config/database.php. For more information on configuring your database, check out the documentation.

    Defining Models

    To get started, let's create an Eloquent model. Models typically live in the app directory, but you are free to place them anywhere that can be auto-loaded according to your composer.jsonfile. All Eloquent models extend Illuminate\Database\Eloquent\Model class.
    The easiest way to create a model instance is using the make:model Artisan command:
    php artisan make:model Flight

    Table Names

    Note that we did not tell Eloquent which table to use for our Flight model. By convention, the "snake case", plural name of the class will be used as the table name unless another name is explicitly specified. So, in this case, Eloquent will assume the Flight model stores records in the flights table. You may specify a custom table by defining a table property on your model:
    <?php
    
    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    
    class Flight extends Model
    {
        /**
         * The table associated with the model.
         *
         * @var string
         */
        protected $table = 'my_flights';
    }

    No comments:

    Post a Comment