title: Retrieve post by category id laravel
body: <p>I want to retrieve all post with given category,
  i am developing api, at input i will receive category name, and then i want to retrieve that category by its id in posts table,i want to do this because if some changed category name in the future i dont have to change that in my code
  i have create like this</p>
  
  <p>PostController.php</p>
  
  <pre><code>  public function getPostsByCategory(Request $request)
  {
  
      $posts=Posts::where('category',$request-&gt;category)-&gt;get();
      return response()-&gt;json(['posts'=&gt;$posts]); 
  }
  </code></pre>
  
  <p>Post model</p>
  
  <pre><code>&lt;?php
  
   namespace App;
  
   use Illuminate\Database\Eloquent\Model;
  
  class Posts extends Model
  {   
  
  protected $fillable = [
      'post_title','post_description', 'category', 'user_id',
  ];
  </code></pre>
  
  <p>Category Model</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Posts_Category extends Model
  {
  
  }
  </code></pre>
  
  <p>can you please help me with this, please suggest me any idea</p>