To integrate your Laravel application with Paragraph, first install our package using Composer:
$ composer require paragraph/laravel
Then, add the following two environment variables to your .env file:
If you are already using Laravel's helper functions and directives like trans(), __() and so on, you can skip this step. We will integrate with that automatically.
Otherwise, wrap any piece of text in your code in our special Blade directive:
@p
Hello there
@endp
Or our global function:
public function index() {
// We are placing a message in the session - "All done"
// It's now wrapped in our helper function p()
return redirect()->back()->with('message', p('All done!'));
}
It's a great idea to render this page so that you can edit texts in-place – on top of the actual designs. To do this, you just have to open any page within the Laravel test suite with Paragraph's special trait enabled. For instance, you could create a file in tests/Paragraph folder with the following contents:
use Paragraph\WithParagraph;
class MyNewTest extends TestCase
{
use WithParagraph;
public function test_a_page_can_be_opened()
{
$this->name('Welcome Page')->get('/');
}
Because our PHP trait extends the Laravel's get() method, this page above will be automatically submitted to Paragraph where we will process the texts and render a snapshot for you.