title: Can't retrive data in view of an one to one polymorphic realation
body: <p>I have a books table and a image table and I also going to have a blog table in future. That's why I want to create a polymorphic relation between book,blog and image table. but my problem is when I tired to retrive data of book image url from the relationship  in view <code>home.blade.php</code> with <code>@foreach</code> I am getting this :</p>
  <p><code>Call to a member function getImage() on null (View: F:\xampp\htdocs\BookReader\resources\views\Main_pages\includes\Home\new_product.blade.php) </code></p>
  <p>codes are given bellow:</p>
  <p><strong>home.blade.php</strong></p>
  <pre><code>@extends('Main_pages.app')
  @section('title','Home')
  @section('content')
      @include('Main_pages.includes.Home.new_product')
  
      @include('Main_pages.includes.Home.testimonial')
  
      @include('Main_pages.includes.Home.popular_products')
  
      @include('Main_pages.includes.Home.news_letter')
  
      @include('Main_pages.includes.Home.blogs')
  
      @include('Main_pages.includes.Home.quick_view')
  @endsection
  </code></pre>
  <p><strong>new_product.blade.php</strong></p>
  <pre><code>&lt;section class=&quot;wn__product__area brown--color pt--80  pb--30&quot;&gt;
  &lt;div class=&quot;container&quot;&gt;
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-lg-12&quot;&gt;
              &lt;div class=&quot;section__title text-center&quot;&gt;
                  &lt;h2 class=&quot;title__be--2&quot;&gt;New &lt;span class=&quot;color--theme&quot;&gt;Products&lt;/span&gt;&lt;/h2&gt;
                  &lt;p&gt;There are many variations of passages of Lorem Ipsum available, but the majority have suffered lebmid alteration in some ledmid form&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;!-- Start Single Tab Content --&gt;
      &lt;div class=&quot;furniture--4 border--round arrows_style owl-carousel owl-theme row mt--50&quot;&gt;
          @foreach($new_books as $book)
          &lt;!-- Start Single Product --&gt;}}
          &lt;div class=&quot;product product__style--3&quot;&gt;
              &lt;div class=&quot;col-lg-3 col-md-4 col-sm-6 col-12&quot;&gt;
                  &lt;div class=&quot;product__thumb&quot;&gt;
                      &lt;a class=&quot;first__img&quot; href=&quot;single-product.html&quot;&gt;&lt;img src=&quot;{{$book-&gt;image-&gt;getImage()}}&quot; alt=&quot;product image&quot;&gt;&lt;/a&gt;
                      &lt;div class=&quot;hot__box&quot;&gt;
                          &lt;span class=&quot;hot-label&quot;&gt;BEST SALLER&lt;/span&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;product__content content--center&quot;&gt;
                      &lt;h4&gt;&lt;a href=&quot;single-product.html&quot;&gt;{{$book-&gt;title()}}&lt;/a&gt;&lt;/h4&gt;
                      &lt;ul class=&quot;prize d-flex&quot;&gt;
                          &lt;li&gt;$35.00&lt;/li&gt;--}}
                          &lt;li class=&quot;old_prize&quot;&gt;$35.00&lt;/li&gt;
                      &lt;/ul&gt;
                      &lt;div class=&quot;action&quot;&gt;
                          &lt;div class=&quot;actions_inner&quot;&gt;
                              &lt;ul class=&quot;add_to_links&quot;&gt;
                                  &lt;li&gt;&lt;a class=&quot;cart&quot; href=&quot;cart.html&quot;&gt;&lt;i class=&quot;bi bi-shopping-bag4&quot;&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
                                  &lt;li&gt;&lt;a class=&quot;wishlist&quot; href=&quot;wishlist.html&quot;&gt;&lt;i class=&quot;bi bi-shopping-cart-full&quot;&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
                                  &lt;li&gt;&lt;a class=&quot;compare&quot; href=&quot;#&quot;&gt;&lt;i class=&quot;bi bi-heart-beat&quot;&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
                                  &lt;li&gt;&lt;a data-toggle=&quot;modal&quot; title=&quot;Quick View&quot; class=&quot;quickview modal-view detail-link&quot; href=&quot;#productmodal&quot;&gt;&lt;i class=&quot;bi bi-search&quot;&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;product__hover--content&quot;&gt;
                          &lt;ul class=&quot;rating d-flex&quot;&gt;
                              &lt;li class=&quot;on&quot;&gt;&lt;i class=&quot;fa fa-star-o&quot;&gt;&lt;/i&gt;&lt;/li&gt;
                              &lt;li class=&quot;on&quot;&gt;&lt;i class=&quot;fa fa-star-o&quot;&gt;&lt;/i&gt;&lt;/li&gt;
                              &lt;li class=&quot;on&quot;&gt;&lt;i class=&quot;fa fa-star-o&quot;&gt;&lt;/i&gt;&lt;/li&gt;
                              &lt;li&gt;&lt;i class=&quot;fa fa-star-o&quot;&gt;&lt;/i&gt;&lt;/li&gt;
                              &lt;li&gt;&lt;i class=&quot;fa fa-star-o&quot;&gt;&lt;/i&gt;&lt;/li&gt;
                          &lt;/ul&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;!-- Start Single Product --&gt;
          @endforeach
      &lt;/div&gt;
      &lt;!-- End Single Tab Content --&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>images migration</strong></p>
  <pre><code>public function up()
  {
      Schema::create('images', function (Blueprint $table) {
          $table-&gt;id();
          $table-&gt;text('url');
          $table-&gt;unsignedBigInteger('imageable_id');
          $table-&gt;text('imageable_type');
          $table-&gt;timestamps();
      });
  }
  </code></pre>
  <p><strong>books migration</strong></p>
  <pre><code>public function up()
  {
      Schema::create('books', function (Blueprint $table) {
          $table-&gt;id();
          $table-&gt;string('book_title');
          $table-&gt;string('book_author');
          $table-&gt;text('book_description');
          $table-&gt;timestamps();
      });
  }
  </code></pre>
  <p><strong>Image Model</strong></p>
  <pre><code>class Image extends Model
  {
      public function imageable(){
          return $this-&gt;morphTo();
     }
      public function getImage(){
          return $this-&gt;url;
     }
  }
  </code></pre>
  <p><strong>Book Model</strong></p>
  <pre><code>class Book extends Model
  {
      public function image(){
          return $this-&gt;morphOne(Image::class,'imageable');
      }
      public function title(){
          return $this-&gt;book_title;
      }
      public function author(){
          return $this-&gt;book_author;
      }
      public function desc(){
          return $this-&gt;book_description;
      }
  }
  </code></pre>
  <p><strong>HomeController</strong></p>
  <pre><code>class HomeController extends Controller
  {
      public function view(){
          $new_books = Book::latest()-&gt;get();
  
          return view('Main_pages.Pages.home',['new_books'=&gt;$new_books]);
      }
  }
  </code></pre>