I am using laravel as a framework and database as a Firebase i want to fetch the data based on the some key value ,for that i wrote following code
<?php
class TestController extends Controller
{
private $database;
public function __construct()
{
$this->database = FirebaseService::connect();
}
public function get(Request $request){
$name = $request->name; //from api request the value is test
$data = $this->database->getReference('/users/')
->orderByValue('name')
->equalTo($name)->getValue();
return response()->json(['data' => $data]);
}
}
but it's throwing following error
Kreait\Firebase\Exception\Database\UnsupportedQuery: Index not defined, add ".indexOn": ".value",
can you please help me to fetch the particular value data ..?
CodePudding user response:
You'd need to set indexOn
users/{uid}/name
, then query with equalTo
:
$snapshot = $this->database
->getReference('users')
->orderByChild('name')
->equalTo($request->name)
->getSnapshot();