vendredi 2 juillet 2021

Trying to get property 'servicio' of non-object

I need to print the name of a service, the problem is that it cannot find the column

controller:

public function index(Request $personal){


    $trabajador = Personal::first();
    $personal = Personal::where('nombre' , $personal)->with('nombre')->get();
    $h = Carbon::now(); 
    $servicios = \App\Models\Eventos::orderByDesc('hora')->get();



    $data = [
        'category_name' => 'apps',
        'page_name' => 'calendar',
        'has_scrollspy' => 0,
        'scrollspy_offset' => '',

    ];


    return view('personal', compact('personal', 'servicios', 'h', 'trabajador',))->with($data);

   

  }

blade.php

@foreach ($servicios as $hoy)
    <td></td>
    <td></td>
@endforeach

Model:

 class Personal extends Model
{
    protected $table= 'personal';

    public function servicio()
    {
        return $this->belongsTo(Servicios::class);
    }
}

the relationship in the database is already done

enter image description here

Why can't I print the name of the service? help please



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire