title: Object of class stdClass could not be converted to string in Laravel on Excel sheet download
body: <p>I was trying to make an Excel sheet in Laravel by joining three tables to make the result of the query to be output in an Excel sheet.</p>
  
  <p>Model to retrieve query result:</p>
  
  <pre><code>&lt;?php
  namespace App;
  use Illuminate\Support\Facades\DB;
  use Illuminate\Database\Eloquent\Model;
  
  class Product extends Model {
      protected $table= 'product_master';
      protected $primaryKey = 'product_id';
  
      public static function download() { 
          $data=DB::table('product_master')
              -&gt;join('subcategory_master', 'product_master.subcategory_id', '=', 'subcategory_master.id')
              -&gt;join('category_master', 'product_master.category_id', '=', 'category_master.id')
              -&gt;select('product_master.product_id','product_master.product_name','product_master.part_number','category_master.category_name','subcategory_master.subcategory_name','product_master.net_quandity','gross_weight','product_master.product_type','product_master.description')
              -&gt;where('delete_status','=','0')-&gt;get();
          return($data);
      }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>&lt;?php
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\Http\Controllers\Controller;
  use App\Product;
  use Excel;
  
  class ExcelController extends Controller {
      public function downloadExcel(Request $request, $type) {
          $data = Product::download()-&gt;all();
  
          return Excel::create('productmaster', function($excel) use ($data) {
              $excel-&gt;sheet('mySheet', function($sheet) use ($data) {
                  $sheet-&gt;fromarray($data);
              });
          })-&gt;download($type);
      }
  }
  </code></pre>
  
  <p>Route:</p>
  
  <pre><code>Route::get('downloadExcel/{type}', 'ExcelController@downloadExcel');
  </code></pre>