{"id":21341429,"url":"https://github.com/avto-dev/back2front-laravel","last_synced_at":"2025-07-12T14:34:10.729Z","repository":{"id":53139013,"uuid":"152708219","full_name":"avto-dev/back2front-laravel","owner":"avto-dev","description":"Package for backend -\u003e frontend communication in Laravel applications","archived":false,"fork":false,"pushed_at":"2024-05-31T11:39:28.000Z","size":98,"stargazers_count":7,"open_issues_count":0,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-28T05:46:23.055Z","etag":null,"topics":["backend","frontend","laravel"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avto-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-12T07:04:08.000Z","updated_at":"2024-05-31T11:39:16.000Z","dependencies_parsed_at":"2024-01-24T12:44:27.033Z","dependency_job_id":"b7806f24-ce01-4953-935b-044339775881","html_url":"https://github.com/avto-dev/back2front-laravel","commit_stats":{"total_commits":37,"total_committers":8,"mean_commits":4.625,"dds":0.5135135135135135,"last_synced_commit":"26e539446e0298312f708b0b754acaf87d9b8c46"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/avto-dev/back2front-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avto-dev%2Fback2front-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avto-dev%2Fback2front-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avto-dev%2Fback2front-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avto-dev%2Fback2front-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avto-dev","download_url":"https://codeload.github.com/avto-dev/back2front-laravel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avto-dev%2Fback2front-laravel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265003896,"owners_count":23696317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","frontend","laravel"],"created_at":"2024-11-22T00:56:49.993Z","updated_at":"2025-07-12T14:34:10.723Z","avatar_url":"https://github.com/avto-dev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://laravel.com/assets/img/components/logo-laravel.svg\" alt=\"Laravel\" width=\"240\" /\u003e\n\u003c/p\u003e\n\n# Send backend data to frontend for Laravel applications\n\n[![Version][badge_packagist_version]][link_packagist]\n[![PHP Version][badge_php_version]][link_packagist]\n[![Build Status][badge_build_status]][link_build_status]\n[![Coverage][badge_coverage]][link_coverage]\n[![Downloads count][badge_downloads_count]][link_packagist]\n[![License][badge_license]][link_license]\n\nPackage for sending data from backend to frontend JS variable.\n\nPackage a repository of the form `\"key\" =\u003e \"value\"` and methods for converting data to array and JSON.\n\n## Install\n\nRequire this package with composer using the following command:\n\n```bash\n$ composer require avto-dev/back2front-laravel \"^2.0\"\n```\n\n\u003e Installed `composer` is required ([how to install composer][getcomposer]).\n\n\u003e You need to fix the major version of package.\n\nFor publish config and assets execute in console next command:\n\n```bash\n$ php artisan vendor:publish --provider=\"AvtoDev\\\\Back2Front\\\\ServiceProvider\" --force\n```\n\nThis command will publish files `./config/back-to-front.php` with basic setting for package and `public/vendor/back-to-front/front-stack.js` with JavaScript object for getting access to the data.\n\n## Usage\n\n### At backend\n\nTo get the stack object at backend you can use global helper:\n\n```php\n\u003c?php\n\nbackToFrontStack();\n```\n\nor getting object from service container:\n\n```php\n\u003c?php\n\nuse AvtoDev\\Back2Front\\Back2FrontInterface;\n\n/** @var Back2FrontInterface $service */\n$service = resolve(Back2FrontInterface::class);\n```\n\n##### Methods\n\nBack2Front object provides the following public methods:\n\nMethod | Description\n------ | ------------\n`put($key, $value)` | Set variable in stack. Parameter `key` must be a string\n`get($key, [default]): mixed` |  Get value by key\n`has($key): bool`   | Check that key exists in storage\n`forget($key)`      | Remove item from storage\n`toArray(): array`  | Return data in array\n`toJson(): string`  | Return data in JSON encoded\n\nAlso you can iterate object.\n\nBack2Front supports dot notation in `put`, `get`, `has` and `forget` methods.\n\n```php\n\u003c?php\n\nbackToFrontStack()-\u003eput('user.name', 'John Doe');\n```\n\nAt frontend will object:\n\n```json\n{\n    \"user\": {\n        \"name\": \"John Doe\"\n    }\n}\n```\n\n### At frontend\n\nFor output data at frontend you should add following code in your blade-template (preferably in the section `head` of the resulting HTML document):\n\n```html\n\u003cscript type=\"text/javascript\"\u003e\n    Object.defineProperty(window, 'DATA_PROPERTY_NAME', {\n        writable: false,\n        value: {!! backToFrontStack()-\u003etoJson() !!}\n    });\n\u003c/script\u003e\n```\n\n**Or** by blade-directive\n\n```html\n@back_to_front_data('DATA_PROPERTY_NAME')\n```\n\nIt creates property with name equals `DATA_PROPERTY_NAME` for superg lobal object `window` with early added data.\n\nDefault value of DATA_PROPERTY_NAME is 'backend'. If you use custom value and want to use front-stack helper on frontend, than you need call `window.frontStack.setStackName('custom_name');` before helper usage.\n\n**Package contains javaScript helper for access to data object.**\n\nUse it you may adding js file at page:\n\n```html\n\u003cscript src=\"/vendor/back-to-front/front-stack.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n```\n\n\u003e **You also can use it as require.js dependency.**\n\nThis creates `window.frontStack` object which provides following methods:\n\nMethod | Description\n------ | -----------\n`get(key, [default])` |  Get value by key. Supports \"dot\" notation for access to items if in data contains multidimensional arrays.  Returns `undefined` if item don't exists or default value if it set\n`has(key): bool` | Check that key exists in storage\n`all(): object` | Returns data object\n\n### Example\n\nAt backend:\n\n```php\nbackToFrontStack()-\u003eput('user_id', $user-\u003eid);\n```\n\nAt frontend:\n\n```html\n\u003cscript type=\"text/javascript\"\u003e\n    console.log(window.frontStack.get('user_id'));\n\u003c/script\u003e\n```\n\n### Testing\n\nFor package testing we use `phpunit` framework and `docker` with `compose` plugin as develop environment. So, just write into your terminal after repository cloning:\n\n```bash\n$ make build\n$ make latest # or 'make lowest'\n$ make test\n```\n\nFor testing JavaScript code using `Mocha` and `Chai` framework.\n\nRun in console `npm test`. Coverage report will in `coverage/coverage.json` and in `coverage/lcov-report/index.html` for humans.\n\n## Changes log\n\n[![Release date][badge_release_date]][link_releases]\n[![Commits since latest release][badge_commits_since_release]][link_commits]\n\nChanges log can be [found here][link_changes_log].\n\n## Support\n\n[![Issues][badge_issues]][link_issues]\n[![Issues][badge_pulls]][link_pulls]\n\nIf you will find any package errors, please, [make an issue][link_create_issue] in current repository.\n\n## License\n\nThis is open-sourced software licensed under the [MIT License][link_license].\n\n[badge_packagist_version]:https://img.shields.io/packagist/v/avto-dev/back2front-laravel.svg?maxAge=180\n[badge_php_version]:https://img.shields.io/packagist/php-v/avto-dev/back2front-laravel.svg?longCache=true\n[badge_build_status]:https://img.shields.io/github/actions/workflow/status/avto-dev/back2front-laravel/tests.yml\n[badge_coverage]:https://img.shields.io/codecov/c/github/avto-dev/back2front-laravel/master.svg?maxAge=60\n[badge_downloads_count]:https://img.shields.io/packagist/dt/avto-dev/back2front-laravel.svg?maxAge=180\n[badge_license]:https://img.shields.io/packagist/l/avto-dev/back2front-laravel.svg?longCache=true\n[badge_release_date]:https://img.shields.io/github/release-date/avto-dev/back2front-laravel.svg?style=flat-square\u0026maxAge=180\n[badge_commits_since_release]:https://img.shields.io/github/commits-since/avto-dev/back2front-laravel/latest.svg?style=flat-square\u0026maxAge=180\n[badge_issues]:https://img.shields.io/github/issues/avto-dev/back2front-laravel.svg?style=flat-square\u0026maxAge=180\n[badge_pulls]:https://img.shields.io/github/issues-pr/avto-dev/back2front-laravel.svg?style=flat-square\u0026maxAge=180\n[link_releases]:https://github.com/avto-dev/back2front-laravel/releases\n[link_packagist]:https://packagist.org/packages/avto-dev/back2front-laravel\n[link_build_status]:https://github.com/avto-dev/back2front-laravel/actions\n[link_coverage]:https://codecov.io/gh/avto-dev/back2front-laravel/\n[link_changes_log]:https://github.com/avto-dev/back2front-laravel/blob/master/CHANGELOG.md\n[link_issues]:https://github.com/avto-dev/back2front-laravel/issues\n[link_create_issue]:https://github.com/avto-dev/back2front-laravel/issues/new/choose\n[link_commits]:https://github.com/avto-dev/back2front-laravel/commits\n[link_pulls]:https://github.com/avto-dev/back2front-laravel/pulls\n[link_license]:https://github.com/avto-dev/back2front-laravel/blob/master/LICENSE\n[getcomposer]:https://getcomposer.org/download/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favto-dev%2Fback2front-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favto-dev%2Fback2front-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favto-dev%2Fback2front-laravel/lists"}