PHP code example of johnnyfreeman / laravel-turbo

1. Go to this page and download the library: Download johnnyfreeman/laravel-turbo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

johnnyfreeman / laravel-turbo example snippets


class PostCommentController
{
    public function store(Request $request, Post $post)
    {
        $comment = $post->comments()->create([
            'text' => $request->get('text')
        ]);

        if ($request->wantsTurboStream()) {
            return turbo_stream()
                ->prepend('comments', view('posts.comment', ['text' => $comment->text]))
                ->append('notifications', view('notifications.simple', ['title' => 'Post comment created!']));
        }

        return back();
    }
}