Create model in laravel updated

    By: Manu
    2 years ago

    Creating a model in laravel


    Creating a model in laravel is easy. we just need to run a command and Laravel will do most of the job. So here i am creating NotificationStatus Model. Models should be named singular and controller should be names plural.

    So here is the command

    php artisan make:model NotificationStatus
    

    After running this you should see this message

    Now you have a model created find it under

    App directory. If you have a separate directory for Models then move this model to that directory and change the

    namespace accordingly.

    Out of the Box Model looks like this

    <?php
    
    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    
    class NotificationStatus extends Model
    {
        //
    }
    


    you can define table name in your model

    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    
    class NotificationStatus extends Model
    {
       /**
        * The table associated with the model.
        *
        * @var string
        */
       protected $table = 'notifications_status_table_name';
    }
    

    You can define Primary key and fillables and more to check what options do you have refer to this link

    Laravel Model

    Hope this helps.