I have a model called Inmueble
, its attributes are:
id_ubicacion
) id_tipo_inmueble
) This model has its respective driver (it should be noted that this driver only brings the CRUD methods by default) and their respective views.
I also have a model Ubicacion
, whose attributes are:
Also with its respective driver and view.
In the same way with the model, controller and view for TipoInmueble
(this model has the same attributes as Location)
The problem I have is that I do not know how to relate the models correctly, since, as I mentioned earlier, the location and the type of property are attributes of the property.
I had read something about methods hasOne
and hasMany
, but I did not know how they should be used, if they are accessors or modifiers, in general, I have no idea where and how to use them, and I did not understand the documentation that laravel has .
In addition to this, I am making the registration form of Inmueble
in laravel collective, and I want to make a selection that shows me the available options in location and type of property, as that information is something that comes from the base of data, in the method that the form shows me, I am also sending this data in an array in the following way:
public function create() {
$ubicaciones = Ubicacion::pluck('nombre', 'id');
$tipoInmueble= TipoInmueble::pluck('nombre', 'id');
return view('properties.create', compact('ubicaciones'), compact('tiposInmueble'));
}
But I'm not sure if it's the right way to do it, I mean the structure I'm using, I'm programming in Java, and it's not usually done that way, so I wanted to ask if this should be done, I'm using 2 models that do not correspond to my controller (Models TipoInmueble
and Ubicacion
when my controller is ControladorInmueble
), I do not know if I should work like this, or use the driver of each model, or work it in another way, I would appreciate it if Could you solve my doubts?