title: Laravel not fetching result from mongodb
body: <p>I have a json file called "University.json" which contains only one row of records.</p>
  
  <pre><code>{"University": [{"fees": "$200"}, {"month": "June"}]}
  </code></pre>
  
  <p>Now I have used mongo import to insert the above *.json file into MongoDb.</p>
  
  <pre><code>mongoimport --db university --collection finance --file University.json 
  </code></pre>
  
  <p>My Mongo database/collection values are : university/finance
  To show the values on view blade from MongoDb , I have tried as below but not able to show the return result. Also, I have a top level element in my json file which is "University". So, is this the proper way to fetch the nested elements. Please suggest.</p>
  
  <h1>Route (web.php)</h1>
  
  <pre><code>Route::group(['middleware' =&gt; ['auth']], function () {
       Route::get('/finance', 'FeesController@getFees');
  });
  </code></pre>
  
  <h1>Controller (FeesController.php)</h1>
  
  <pre><code>...
  public function getFees()
      {
          $fees = Finance::all();
          return view('tables', compact('fees'));
      }
  ...
  </code></pre>
  
  <h1>Model (Finance.php)</h1>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
  
  
  class Finance extends Eloquent
  {
      protected $connection = 'mongodb';
      protected $collection = 'finance';
  
      protected $fillable = [
          'fees', 'month'
      ];
  }
  </code></pre>
  
  <h1>View blade (tables.blade.php)</h1>
  
  <pre><code>&lt;tr&gt;
          &lt;th&gt;fees&lt;/th&gt;
          &lt;th&gt;Month&lt;/th&gt;
      &lt;/tr&gt;
  
        @foreach($fees as $fee)
        &lt;tr&gt;
          &lt;td&gt;{{$fee-&gt;fees}}&lt;/td&gt;
          &lt;td&gt;{{$fee-&gt;month}}&lt;/td&gt;
        &lt;/tr&gt;
        @endforeach
  </code></pre>
  
  <h1>. env file</h1>
  
  <pre><code>MONGODB_CONNECTION=mongodb
  MONGODB_HOST=127.0.0.1
  MONGODB_PORT=27017
  MONGODB_DATABASE=university
  MONGODB_USERNAME=
  MONGODB_PASSWORD=
  </code></pre>
  
  <h1>database.php</h1>
  
  <pre><code>...
      'default' =&gt; env('DB_CONNECTION', 'mysql'),
          'mongodb' =&gt; [
                      'driver'   =&gt; 'mongodb',
                      'host'     =&gt; env('MONGODB_HOST', 'localhost'),
                      'port'     =&gt; env('MONGODB_PORT', 27017),
                      'database' =&gt; env('MONGODB_DATABASE', 'university'),
                      'username' =&gt; env('MONGODB_USERNAME'),
                      'password' =&gt; env('MONGODB_PASSWORD'),
                      'options'  =&gt; [
                          'database' =&gt; 'admin' // sets the authentication database required by mongo 3
                      ]
                  ],
  
      'mysql' =&gt; [
                  'driver' =&gt; 'mysql',
                  'url' =&gt; env('DATABASE_URL'),
                  'host' =&gt; env('DB_HOST', '127.0.0.1'),
                  'port' =&gt; env('DB_PORT', '3306'),
                  'database' =&gt; env('DB_DATABASE', 'forge'),
                  'username' =&gt; env('DB_USERNAME', 'forge'),
                  'password' =&gt; env('DB_PASSWORD', ''),
                  'unix_socket' =&gt; env('DB_SOCKET', ''),
                  'charset' =&gt; 'utf8mb4',
                  'collation' =&gt; 'utf8mb4_unicode_ci',
                  'prefix' =&gt; '',
                  'prefix_indexes' =&gt; true,
                  'strict' =&gt; true,
                  'engine' =&gt; null,
                  'options' =&gt; extension_loaded('pdo_mysql') ? array_filter([
                      PDO::MYSQL_ATTR_SSL_CA =&gt; env('MYSQL_ATTR_SSL_CA'),
                  ]) : [],
              ],
  ...
  </code></pre>
  
  <h1>app.php</h1>
  
  <pre><code>...
  /*
      `Mongo DB
      */
      Jenssegers\Mongodb\MongodbServiceProvider::class,
  ...
  </code></pre>
  
  <p>Note : I am using both mysql and mongodb for my requirements. There is no issue while attempting simple json structure without top level element.</p>
  
  <h1>Edit (1) :</h1>
  
  <p>I have changed the controller function as :</p>
  
  <pre><code>public function getFees()
  {
  $fees = Finance::where(['University.month' =&gt; 'June'])-&gt;get();
     return view('tables')-&gt;with('fees', json_decode($fees, true));
  }
  </code></pre>
  
  <p>and simply print the below in view blade shows the entire Json structure from mongo. </p>
  
  <pre><code>{!! json_encode($fees) !!}
  </code></pre>
  
  <p>output :</p>
  
  <pre><code>[{"_id":"5e04a06ca445f78401a16d0a","University":[{"fees":"$200"},{"month":"June"}]}]
  </code></pre>
  
  <p>But now how to separate the elements ? 
  I want to show Fees = $200 and Month = June in the blade view.</p>
  
  <p>I have tried but not working and giving undefined index exception fees in view.</p>
  
  <pre><code>@foreach($fees['member'] as $member)
      Fees: {{ $member['University']['fees'] }}
      Month: {{ $member['University']['fees'] }}
  @endforeach
  </code></pre>
  
  <p>Final solution shown in another question. may be helpful if someone facing similar situation.</p>
  
  <p><a href="https://stackoverflow.com/questions/59493934/laravel-how-to-split-fetch-the-json-nested-elements-in-blade-view#59496527">Laravel : How to split/fetch the json nested elements in blade view?</a></p>