I am learning laravel, when running a page I get the following error. It says that I need a model, but I don't know in which part. I get the following error
TypeError: Cannot read properties of undefined (reading '$model')
at Proxy.render (42.js:4852:74)
at 1.js:1679:80
at activateCurrentInstance (1.js:1639:16)
at $options.render (1.js:1679:24)
at Vue._render (app.js:144739:22)
at VueComponent.updateComponent (app.js:145238:22)
at Watcher.get (app.js:145661:25)
at Watcher.run (app.js:145736:22)
at flushSchedulerQueue (app.js:145494:13)
at Array.<anonymous> (app.js:143165:12)
I have my two tables,
"orders"
id
created_at
updated_at
poliza_garantia
id_poliza
"polizas_garantia"
id
created_at
updated_at
orden_id
importe
fecha_activacion
A radiogroup appears on a screen that does include a guarantee policy, poliza_garantia = 1 and two fields appear and the data added in those two fields (importe and fecha_activacion) will be saved in the table polizas_garantia
this is my view in vue Here two fields are enabled if the radiogroup "poliza_garantia" is selected, if "poliza_garantia" is equal to 1 (if selected), the CInputs appear
<CCol sm="3">
<label for="">¿Does it include a warranty policy?</label>
<CInputRadioGroup
:options="poliza_garantia_lst"
:inline=true
:checked.sync="v$.orden.poliza_garantia.$model"
:invalid-feedback="
v$.orden.poliza_garantia.$error
? v$.orden.poliza_garantia.$errors[0].$message
: ''
"
:is-valid="
v$.orden.poliza_garantia.$dirty
? !v$.orden.poliza_garantia.$invalid
: null
"
/>
</CCol>
<CCol sm="2" v-if="orden.poliza_garantia == 1">
<CInput
:value.sync="polizagarantia.importe"
:plain="true"
label="Importe de poliza de garantia"
placeholder="Importe"
:invalid-feedback="
v$.polizagarantia.importe.$error
? v$.polizagarantia.importe.$errors[0].$message
: ''"
:is-valid="v$.polizagarantia.importe.$dirty
? !v$.polizagarantia.importe.$invalid : null"
/>
</CCol>
<CCol sm="3" v-if="orden.poliza_garantia == 1">
<CInput
:value.sync="polizagarantia.fecha_activacion"
label="Fecha de activacion de la poliza de garantia (Considerando que esta instalado el proyecto)"
type="date"
>
</CInput>
</CCol>
Here are the instances and validations of the vue
PolizasGarantia: {
importe: "",
fecha_activacion: "",
},
Orden: {
poliza_garantia: "",
id_poliza: "",
test_poliza: "",
}
data() {
return {
poliza_garantia_lst: [
{ value: 1, label: 'Si'},
{ value: 0, label: 'No'}
]}
polizagarantia: {
importe: "",
fecha_activacion: "",
},
orden: {
poliza_garantia: "",
id_poliza: "",
test_poliza:"",
validations(){
return{
orden:
id_poliza: {required: requiredIf(() => this.orden.poliza_garantia == 1), $autoDirty: true},
}
}
polizagarantia:{
importe: {required: requiredIf(() => this.orden.poliza_garantia == 1), numeric, $autoDirty: true},
fecha_activacion: {required: requiredIf(() => this.orden.poliza_garantia == 1), $autoDirty: true},
}
This is my Controller
public function addOrden(Request $request)
{
$request->validate([
'poliza_garantia' => 'required|min:1|max:30',
'id_poliza' => 'required|min:1|max:50',
'test_poliza' => 'max:10',
'importe' => 'max:15',
'fecha_activacion' => 'max:15',
if($request->input("poliza_garantia") == 1 ){
$polizagarantia = new PolizaGarantia();
$polizagarantia->importe = $request->input("importe");
$polizagarantia->fecha_activacion = $request->input("fecha_activacion");
$polizagarantia->save();
}
$orden = new Orden();
if($request->input("poliza_garantia") == 1 ){
$orden->id_poliza = $polizagarantia->id;
}
if($request->input("poliza_garantia") == 0){
$orden->id_poliza = NULL;
}
$orden->test_poliza = $request->input("test_poliza");
$orden->poliza_garantia = $request->input("poliza_garantia");
$orden->id_poliza = $request->input("id_poliza");
if($request->input("poliza_garantia") == 1 ){
$polizagarantia->orden_id = $orden->$id;
$polizagarantia->save();
}else
$polizagarantia=null;
return response()->json(compact('orden','AImayor','polizagarantia'));
}
This is my model
PolizasGarantia.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PolizaGarantia extends Model
{
use HasFactory;
protected $table = 'polizas_garantia';
protected $dates = ['created_at', 'updated_at', 'fecha_activacion'];
// public function Polizas()
// {
// return $this->belongsTo('App\Models\Polizas', 'id_poliza');
// }
public function Orden()
{
return $this->belongsTo('App\Models\Orden', 'id_poliza');
//return $this->belongsTo('App\Models\Orden', 'orden_id');
}
public function registerMediaCollections(): void
{
$this->addMediaCollection('importe')->singleFile();
$this->addMediaCollection('fecha_activacion')->singleFile();
}
}
The model Orden.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class Orden extends Model implements HasMedia
{
use InteractsWithMedia;
use HasFactory;
protected $table = 'ordenes';
protected $dates = [
'created_at', 'updated_at', 'fecha_inicio', 'fecha_instalacion', 'fecha_fin', 'fecha_deposito'
];
// protected $appends = ['semaforo', 'liquidacion', 'documento', 'fecha_programado', 'fecha_proceso', 'fecha_proceso_cfe', 'fecha_si_asignado', 'fecha_finalizado'];
protected $appends = ['semaforo'];
protected $fillable = [];
public function polizagarantia()
{
$sub = $this->belongsTo('App\Models\PolizasGarantia', 'orden_id');
return $sub;
}
- I tried to solve it but I couldn't