Using laravel 5.1, could I insert a custom code into a blade view dynamically?
For example, I have this view.blade.php
:
<html>
<head>
<title>App Name - @yield('title')</title>
</head>
<body>
@section('sidebar')
This is the master sidebar.
@show
<div class="container">
@yield('content')
// Here, I want to insert a code dynamically, for example :
<div> <p> something </p> </div>
</div>
</body>
So, Is there a good way to do something like this in controller :
$customCode = "<div> <p> something </p> </div>";
$content = (string) $view;
//For example I want to insert this code into view file on line 11
updateContent($content, $customCode, $line_position_in_view);
Here is your code with jQuery :
Your HTML FILE OR VIEW FILE
<div class="container">
@yield('content')
// Here, I want insert a code dynamically, for example :
<div> <p> something </p> </div>
</div>
$.post("test.php",{},function (data){
$(".container").append(data);
});
Note : if you want to use controller function then change test.php
with function name with proper path.
test.php file or controller function
<?php
echo "<div> <p> something </p> </div>";
exit;
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With