Reputation: 1
can i put jquery on the laravel controller? because I need to use jquery to pull data from the database to the combobox, and the code view that has been created is placed in the controller
Upvotes: 0
Views: 293
Reputation: 1
You can write html with php code by concatenation. Same as you can put your JavaScript or jquery code inside html code by concatenation in script tag.
Example:
$phpcode .= "<h1> hello </h1>
<script>
$(document).ready(function() { alert('hello');});
</script>
"
Upvotes: 0
Reputation: 2092
You can't use JQuery inside a controller, PHP and Javascript don't mix like this, both of them have different roles when building a website/app.
What you can do is to use JQuery inside your blade
files and use AJAX to perform calls to your controllers requesting data. After that you can use JQuery to manipulate DOM elements based on the data sent by the Laravel controllers.
Upvotes: 1