i usually get this error: Illegal string offset 'Firstname' (View: C:\xampp\htdocs\cars\resources\views\pages\home.blade.php)

Posted 9 months ago by icelander

hi. below is my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;


class FirebaseController extends Controller
{
  public function index(){

$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/FirebaseKey.json');
$firebase = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->create();

    $database = $firebase->getDatabase();

    $ref=$database->getReference("users");
    $users=$ref->getValue();

    foreach($users as $user){
        $all_user[] =$user;
    }

    return view('pages.home',compact('all_user'));

  }
}

this is my view

<table id="example1" class="table table-bordered table-striped">
        <thead>
        <tr>
         <th>S/No</th>
          <th>First Name</th>
          <th>Last Name</th>
          <th>Phone Number</th>
          <th>Email</th>
          
        </tr>
        </thead>
        <tbody>
            @foreach($all_user as $user)
        <tr>
          <td>Trident</td>
          <td> {{$user["Firstname"]}}
          {{-- </td>
          <td>{{$user['Lastname']}}</td>
          <td> {{$user['email']}}</td>
          <td>{{$user['Phone']}}</td>
        </tr> --}}
        @endforeach
    ```
pls help

Please sign in or create an account to participate in this conversation.