Are Getters and Setters automatically generated by Eloquent when we use reliese/Standard to generate Modules?

Asked

Viewed 249 times

0

I have an application already functional. I am switching to Laravel 5.4. Since the database already exists and with actual data, my choice is not to use Migrations. One option would be to use the Query Builder to access the data in the database. But I didn’t want to leave behind some conveniences offered by Eloquente. So I decided to import the database model into the ORM using the reliese/Laravel, and at the end of the process the Templates are created in the folder app/Models/Minhatabela.php.

As I am a beginner in Laravel I don’t know which methods are created automatically when we generate the Models. It caught my attention that there were not created getters and setters automatically for each field or attribute of each table. In Sinfony there is a function of the Doctrine, which after the creation of the Entities (equivalent to the Eloquent Models) this function generates getters and settersfor each field of the table.

This is an example of the automatically generated code for the Model table Country:

<?php

/**
 * Created by Reliese Model.
 * Date: Mon, 06 Mar 2017 02:14:38 +0000.
 */

namespace App\Models;

use Reliese\Database\Eloquent\Model as Eloquent;

/**
 * Class Country
 * 
 * @property int $id
 * @property string $name
 * @property string $iso3_code
 * @property string $iso2_code
 * @property string $geocodeBr
 * @property float $lat
 * @property float $long
 * 
 * @property \Illuminate\Database\Eloquent\Collection $provinces
 *
 * @package App\Models
 */
class Country extends Eloquent
{
    protected $table = 'country';
    public $timestamps = false;

    protected $casts = [
        'lat' => 'float',
        'long' => 'float'
    ];

    protected $fillable = [
        'name',
        'iso3_code',
        'iso2_code',
        'geocodeBr',
        'lat',
        'long'
    ];

    public function provinces()
    {
        return $this->hasMany(\App\Models\Province::class, 'fk_country');
    }
}

As it turns out, virtually nothing was created, I would have to create the setters and getters and put delete, etc., for each field of each table.

When we have a database with 200 tables it gets boring.

So my question is whether getters and setters are automatically generated by some Eloquent command or would I have to automatically create each of them? If yes what command would that be?

  • 1

    Elqouent does not generate methods get/setter as an example getId() and setId($value), actually would be id, name, the names that are in your table. Nothing prevents you to create by hand, but, already reported that is inconvenient, also believe it is, I think unnecessary, because Eloquent does it differently and is an additional code without need, use the standard nomenclature ...

  • Like I said, I’m new to Laravel. I did some research and then I thought we didn’t need getters and setters, like you said. When the Model extends the Eloquent class it already inherits the functions of the Eloquent class that would be getters and setters, such as self::all(), which would be getAll(). And so on and so forth...

  • 1

    not everything you said in the above message is so automatically generates has more things to learn about Laravel which is actually PHP, continue studying ... @zwitterion

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.