Quay lại Trending
RepositoryPHPBEBỉ
SP

spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

618sao
36fork
0issue
2lượt xem

🛠️ Export biến PHP sang JavaScript trong Blade Laravel

Một Blade directive nhỏ nhưng tiết kiệm thời gian khi cần truyền dữ liệu từ server lên client.

Dự án laravel-blade-javascript của Spatie cung cấp directive @javascript giúp xuất giá trị từ PHP ra JavaScript trong view Blade. Thay vì viết tay thẻ <script>, chỉ cần một dòng và giá trị được gán trực tiếp vào đối tượng window.

✨ Điểm nổi bật

  • @javascript('key', 'value'): Xuất một cặp khóa-giá trị ra JavaScript.
  • @javascript(['key' => 'value']): Hỗ trợ truyền mảng để xuất nhiều giá trị cùng lúc.
  • Cấu hình namespace: Tùy chỉnh namespace chứa các biến JavaScript.
  • Tùy biến thẻ script: Có thể publish view để thêm thuộc tính như type hoặc CSP nonce.
  • Tự động đăng ký: Không cần cấu hình thủ công, chỉ cần cài qua Composer.
  • Hỗ trợ cấu hình và view tùy chỉnh: Publish config hoặc view dễ dàng.

💡 Vì sao đáng chú ý

Thay vì sử dụng json_encode và nhúng thủ công vào Blade, package này đưa quy trình lên một cấp độ trừu tượng nhẹ nhàng. Phù hợp với các ứng dụng Laravel cần truyền cấu hình, dữ liệu người dùng hoặc bất kỳ giá trị nào từ backend lên frontend mà không cần viết API riêng.


#Laravel #Blade #PHP #JavaScript #Spatie #TiniX

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryPHP
roots/sage

WordPress starter theme with Laravel Blade components and templates, Tailwind CSS, and block editor support

13.3k
Nov 23, 2026
RepositoryTypeScript
morluto/rea

Reverse engineer anything with agents, from app behavior down to native binaries.

487.0k
Dec 2, 2026
RepositoryTypeScript
freeCodeCamp/freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.

459.9k
Dec 2, 2026
RepositoryPython
practical-tutorials/project-based-learning

Curated list of project-based tutorials

290.9k
Nov 30, 2026
RepositoryJavaScript
react/react

The library for web and native user interfaces.

253.0k
Nov 30, 2026
RepositoryTypeScript
vuejs/vue

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core

212.6k
Oct 10, 2024
RepositoryJavaScript
trekhleb/javascript-algorithms

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

196.8k
Jul 26, 2026
Repository
getify/You-Dont-Know-JS

A book series (2 published editions) on the JS language.

184.8k
Oct 31, 2026
RepositoryPHP
laravel/framework

Laravel is a web application framework with expressive, elegant syntax.

35.3k
Nov 30, 2026