1. Go to this page and download the library: Download hihaho/laravel-js-store library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hihaho / laravel-js-store example snippets
// Using the helper
frontend_store()->put('user', Auth::user());
// Using the facade
\HiHaHo\LaravelJsStore\StoreFacade::put('user', Auth::user());
// Using the laravel container
app()->make(\HiHaHo\LaravelJsStore\Store::class)->put('user', Auth::user());
app()->make('js-store')->put('user', Auth::user());
// Using the view or response macro
class Controller
{
public function index()
{
return view('index')
->js('foo', 'bar');
}
public function create()
{
return response()
->view('create')
->js([
'foo' => 'Fred',
'bar' => 'Waldo',
]);
}
}
namespace App\Http\FrontendDataProviders;
use HiHaHo\LaravelJsStore\AbstractFrontendDataProvider;
class User extends AbstractFrontendDataProvider
{
/**
* The data that will be JSON encoded
*
* @return mixed
*/
public function data()
{
return Auth::user();
}
public function hasData(): bool
{
// Only push the data when the user is signed in
return Auth::check();
}
}