title: Laravel eloquent vs query builder pros and cons
body: <p>Whenever I make a laravel project, I always define relationships not just in the model but also in the database (I always do a <code>php artisan make:model ModelName -mcr</code>). Sometimes I saw code that they only define relationships in model but not in the database and vice versa. Can someone tell me what are their differences and should I always define relationships in the model and in the database or should I do in one of them? Also, I always use both laravel eloquent queries and laravel query builder which is <code>DB::table</code>. What are the pros and cons of using both? Which are faster? Tell me your opinions and advice. I hope you get my point. Thanks</p>
  
  <p>Sample Model</p>
  
  <pre><code>public function damage(){
          return $this-&gt;hasMany('App\Product');
      }
  </code></pre>
  
  <p>Sample Table</p>
  
  <pre><code>
          Schema::table('damages', function($table)
          {
              $table-&gt;foreign('product_id')
                      -&gt;references('id')
                      -&gt;on('products')
                      -&gt;onDelete('cascade');
          });
  </code></pre>
  
  <p>Sample query</p>
  
  <pre><code>  public function getDamages(){
          $damages = DB::select(
              "SELECT damages.product_id, damages.quantity, damages.price, products.product_name
              FROM damages
              JOIN products on damages.product_id = products.id"
             );
          return view('damages', compact('damages'));
  
  //or
  
   $recipes = DB::table('recipes')
              -&gt;join('category_recipe', 'recipes.id', '=', 'category_recipe.recipe_id')
              -&gt;join('category', 'category.id', '=', 'category_recipe.category_id')
              -&gt;join('users', 'users.id', '=', 'recipes.user_id')
              -&gt;where('category.id', '=', $cat_id)-&gt;get(array('recipes.*','users.*'));  
  
      }
  </code></pre>
  
  <p>Sample query 2</p>
  
  <pre><code>public function index(){
         $damage = Damage::all();
  //or
         $suppliers = Supplier::all()-&gt;where('status', 'active');
  //or
         $recipes = Recipe::with('category')-&gt;where('category_id',$cat_id)-&gt;get();  
  
  }
  </code></pre>