Trying to get property ‘name’ of non-object in laravel 7

  laravel, laravel-7, php

i have two tables Products and Category i have defined there realtionship
in my category.php

 public function Products()
        {
            return $this->belongsTomany(Product::class);
        }

and in my product.php

 public function Cat()
    {
        return $this->belongsTo(Category::class);
    }

in my blade template i am trying to get the name of the category by using

@foreach($products as $pro)
                            <tr>
                              
                            <td><img src="{{asset('uploads/maj/'.$pro->image)}}" class="img-circle" alt="User Image" width="50" height="50"> </td>
                            <td> 
                           
                           {{$pro->Cat->name}}

i have also defined the category_id field in my Products table

Schema::create('products', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('category_id');
            $table->string('name');
            $table->string('code');
            $table->string('color');
            $table->string('description');
            $table->double('price');
            $table->integer('quantity');
            $table->string('image');
            $table->timestamps();
        });

i am trying to get the name of the category but i am unable to do so . can anyone explain me what i have did wrong i would be highly thank ful regards
my laravel version is 7.

Source: Ask PHP

LEAVE A COMMENT