title: How to make one to many relationship in laravel
body: <p>I'm trying to make a one to many relationship using eloquent model and want to show the products in the specified category 
  that is my product model : </p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  use Illuminate\Database\Eloquent\softDeletes;
  
  class Product extends Model
  {
      use softDeletes;
      protected $table='products';
  
      public function category(){
          return $this-&gt;belongsTo('App\Category');
      }
  }
  </code></pre>
  
  <p>And that is my category model : </p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  use Illuminate\Database\Eloquent\softDeletes;
  
  class Category extends Model
  {
      use softDeletes;
      protected $table='category';
  
     public function product(){
      return $this-&gt;hasMany('App\Product','category_id','id');
     }
  }
  </code></pre>
  
  <p>And that's the product controller : </p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  
  use App\Http\Requests;
  use App\Http\Controllers\Controller;
  use App\Product;
  use App\Category;
  
  class productsController extends Controller
  {
      public function getShow($id,Request $request){
              $in=$request-&gt;get('id');
              $category=Category::all();
              $product=Product::find($id);
              $products=$product-&gt;category()-&gt;where('category_id','=',$in);
  
              return view ('contents.products')-&gt;with('products',$products)
                                              -&gt;with('category',$category);
      }
  }
  </code></pre>
  
  <p>And this is the product table :  </p>
  
  <pre><code>public function up()
  {
      Schema::create('products', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('name');
          $table-&gt;string('category_id');
          $table-&gt;string('describtion');
          $table-&gt;string('image_name');
          $table-&gt;timestamps();
          $table-&gt;softDeletes();
      });
  }
  </code></pre>
  
  <p>And that is the category table :  </p>
  
  <pre><code>public function up()
  {
      Schema::create('category', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('name');
          $table-&gt;timestamps();
          $table-&gt;softDeletes();
      });
  }
  </code></pre>
  
  <p>And it gives me this error : Call to a member function category() on a non-object</p>
  
  <p>So how can i solve it ? </p>