mercredi 21 juillet 2021

Trying to get property 'fechaviso' of non-object

I am new to Laravel, I need help with this error:

Property [fechaviso] does not exist on this collection instance

public function retiro(Request $request) {
    $data = [
        'category_name' => 'datatable',
        'page_name' => 'miscellaneous',
        'has_scrollspy' => 0,
        'scrollspy_offset' => '',
    ];

    $registros = Registro::whereNull('retiro')
        ->whereNull('retiro')
        ->get();

    $hoy = Carbon::now();
    $update = Registro::where('id', $request->id)->first();
    $registro = Registro::find($request->id);
    
    //fecha1 = date
    //fecha2 = today

    $fecha1 = $registro->fechaviso;
    $fecha2 = new DateTime();
    $contadorfecha = $fecha1->diff($fecha2);

    if ($request->isMethod('put')) {
        if ($update->retiro = $request->retiro) {
            $update->fecharetiro = Carbon::now();
        }

        $update->save();

        return redirect('retirados');
    }
  
    return view('retiro', compact('registros', 'update', 'hoy', 'contadorfecha'))->with($data);
}

I am calculating the difference between days:

@foreach($registros as $registro)
    <tr>
        <td class="checkbox-column">1</td>
        <td></td>
        <td></td>
        <td></td>
        <td>
            <span class="shadow-none badge badge-primary"></span>
        </td>
        <td class="text-center"></td>
    </tr>
@endforeach

database

I am getting an error:

Trying to get property 'fechaviso' of non-object

I should be able to calculate the days difference, I tried this query but it did not work: Registro::find($request->id);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire