PHP code example of cretueusebiu / laravel-javascript
1. Go to this page and download the library: Download cretueusebiu/laravel-javascript 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/ */
cretueusebiu / laravel-javascript example snippets
namespace App\Http\Controllers;
use Eusebiu\JavaScript\Facades\ScriptVariables;
class HomeController extends Controller
{
public function home()
{
ScriptVariables::add('key', 'value');
ScriptVariables::add('data.user', User::first());
}
}
{{ ScriptVariables::render() }}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Eusebiu\JavaScript\Facades\ScriptVariables;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
ScriptVariables::add(function () {
return [
'csrfToken' => csrf_token(),
'currentUser' => auth()->user(),
];
});
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.