Laravel with firebase

Asked

Viewed 41 times

-1

I was wondering if there is any way to simulate that Firebase system (which is not yet compatible with PHP) to receive the information from the database in real time. I’m using Laravel, I collect the information by Controller and send it to view via array. I know there is a Broadcasting, but do not know if it would be the right option in this situation, also do not know very well how to implement. An example of the operation:

CONTROLLER:

function index(){
    $database = app('firebase.database');
    $drinks = $database->getReference('Drinks')->getSnapshot();

    return view('welcome', [
       'drinks' => $drinks->getValue()
    ]);
}

VIEW:

@foreach($drinks as $key => $drink)
    <div class="row">
        <div class="cell" data-title="Bebida">{{$drink['name']}}</div>
        <div class="cell" data-title="Preço">R$ {{sprintf("%01.2f", $drink['price'])}}</div>
        <div class="cell" data-title="Id">{{$key}}</div>
        <div class="cell" data-title="Ações">
            <div class="container-buttons">
                <a href="delete/{{$key}}"><button type="button" class="btn btn-outline-danger">Excluir</button></a>
                <a href="edit/{{$key}}"><button type="button" class="btn btn-outline-success">Editar</button></a>
            </div>
        </div>
    </div>
@endforeach

1 answer

-3


I think it is not possible, because real-time firebase updates need to be on the client’s side...

Note: Real-time listeners are not compatible with the PHP client library.

I recommend that you javascript the client this query.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.