Laravel Playground allows you to prefill your embeds. This allows you to keep the code that you want to embed entirely on your own website - say for a blog post.
Let's say that you want to include this piece of PHP code in your blog post:
$slice = Str::of('This is my name')->after('This is');
Laravel Playgrounds prefill embeds can now execute this PHP code for you in a sandboxed environment. This means that you keep your code on your website and Laravel Playground executes and renders it for you.
Here's the example code embedded:
<?php
$slice = Str::of('This is my name')->after('This is');
dd($slice);
The embed code that makes this work is very developer friendly. You can keep your code wrapped in <pre> or <code> blocks on your website and wrap them in a <div> with attributes that control the embed, like this:
<div
class="laravel-playground"
data-height="500px"
>
<pre data-filename="index.php">
<?php
$slice = Str::of('This is my name')->after('This is');
dd($slice);
</pre>
</div>
<script src="https://embed.laravelplayground.com"></script>
Your prefill embeds can also include multiple files at once. For each file that you want to embed, you can add one <pre> or <code> element with a data-filename attribute that determines the filename that you want to use. Here's an example that loads a file called index.php and a view called embedded.blade.php.
<?php
Route::get('/', function() {
return view('embedded');
});
<h1>I got embedded!</h1>
To open a different file, click on the arrow icon next to the filename.
This is the code that powers the above embedded playground.
<div
class="laravel-playground"
data-height="500px"
>
<pre data-filename="index.php">
<?php
Route::get('/', function() {
return view('embedded');
});
</pre>
<pre data-filename="embedded.blade.php">
<h1>I got embedded!</h1>
</pre>
</div>
<script src="https://embed.laravelplayground.com"></script>
Our course teaches you how to build, publish, and distribute desktop applications with HTML, JavaScript and CSS.
Learn more