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')

    $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();


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

I am calculating the difference between days:

@foreach($registros as $registro)
        <td class="checkbox-column">1</td>
        <td>{{ $registro->cliente }}</td>
        <td>{{ $registro->tipo }}</td>
        <td>{{ $registro->telefono }}</td>
            <span class="shadow-none badge badge-primary">{{ $contadorfecha }}</span>
        <td class="text-center"></td>


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);

Read more here:

Content Attribution

This content was originally published by jeremias rosas at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: