Created
December 20, 2024 12:00
-
-
Save iamdanre/2f18f533539672972cd6af7c167b5ee6 to your computer and use it in GitHub Desktop.
blade to js object dump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
const user = @json($user); | |
console.log(user); | |
</script> | |
<script> | |
const user = {!! json_encode($user ?? []) !!} | |
console.log(user) | |
<script> | |
/** controller */ | |
use JavaScript; | |
public function boot() | |
{ | |
JavaScript::put([ | |
'user' => auth()->user() | |
]); | |
} | |
/** blade */ | |
<script> | |
const user = window.Laravel.user; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment