Support the ongoing development of Laravel.io →
Configuration Laravel
Last updated 2 years ago.
0

Hello, i am a new dev in Laravel 5

Try it

Config in DB Firebase in panel (Google)

After config your Laravel

Require in composer

composer require kreait/firebase-php ^4.0

enter image description here

Or your add manual in file composer.json

"require": { "kreait/firebase-php": "^4.0" }

create your controller

php artisan make:controller FirebaseController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Kreait\Firebase;
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
use Kreait\Firebase\Database;

class FirebaseController extends Controller{

public function index(){

$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/Laraveltesting-6aeda3a963f2.json');

$firebase = (new Factory)

->withServiceAccount($serviceAccount)
->withDatabaseUri('https://laraveltesting-bd2b9.firebaseio.com/')
->create();

$database = $firebase->getDatabase();
$newPost = $database

->getReference('blog/posts')
->push([
'title' => 'Post title',
'body' => 'This should probably be longer.'
]);

//$newPost->getKey(); // => -KVr5eu8gcTv7_AHb-3-
//$newPost->getUri(); // => https://my-project.firebaseio.com/blog/posts/-KVr5eu8gcTv7_AHb-3-
//$newPost->getChild('title')->set('Changed post title');
//$newPost->getValue(); // Fetches the data from the realtime database
//$newPost->remove();

echo"<pre>";

print_r($newPost->getvalue());
}
}

?>

After set your router

Route::get('/phpfirebase_sdk','FirebaseController@index');

More infos in https://www.cloudways.com/blog/firebase-realtime-database-laravel/

Sorry for my bad english.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.