Complete BLoC with Clean Architecture (group chat) Discount !! E-commerce App With Backend Source Code Video and Voice Chatting App Firebase Chatting App Source Code Complete Gym App BLoC State Management Source Code Complete Study App Buy Ticket Booking App Source Code Buy Travel App With Backend Source Code Complete Chat App Udemy Course Special Offer Discount !! Online Learning Course App (BLoC) Online Learning Course App (Riverpod) Online Learning Course App (Getx) Discount !! Shopping App (Provider) Cool Flutter Game Flutter Nodejs Chat App Flutter Nodejs Api And Firebase Chat App Riverpod Task Management App
In this tutorial I will show you how to send value from controller to Javascript in Blade in Laravel application.
Say you have a value $x=10 in your controller and you want to grab the value in your blade. Then do the following steps to get the value in front end code.
1. Send the value using compact function to blade like below
public function Posts(){
....................
.....................
$x=10;
......................
return view('my_view', compact('x'));
}
2. Now in your javascript retrieve the value like below
<script>
let x = "{{$x}}";
/*
Now you can print it or use the way you want.
*/
console.log(x);
<script>
3. In the above javascript function $x has the value passed from laravel controller.