Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for other resources to be turbo-streamable #26

Merged
merged 1 commit into from
Jun 23, 2021

Conversation

stevebauman
Copy link
Contributor

Purpose

This PR adds the ability for any PHP object to be turbo-streamable by implementing the TurboStreamable interface.

Description

I'm the developer of a PHP package called LdapRecord that heavily integrates into Laravel and want to be able to use turbo-laravel with LdapRecord models. This isn't possible currently, since Eloquent models are type-hinted into this package.

This PR opens the door for any PHP object to be "turbo-streamable" by implementing a getDomId() method.

In my case, this is how I would utilize this with LdapRecord models:

use LdapRecord\Models\Model;
use Tonysm\TurboLaravel\Views\TurboStreamable;

class User extends Model implements TurboStreamble
{
    public function getDomId()
    {
        return $this->getObjectGuid();
    }
}

Notes

The namespace and location of TurboStreamable might need to be changed -- I wasn't sure where you might want this placed or named.

Let me know if you have any comments/concerns/questions. Thanks for your hard work on this package!

@tonysm
Copy link
Collaborator

tonysm commented Jun 21, 2021

I like this. I think the Rails package doesn't require the classes to extend AR either. I know for sure that the dom_id helper supports anything responding to the .to_key message (source). If we did the same here and only required a getKey method in the object, would that help you?

@stevebauman
Copy link
Contributor Author

If we did the same here and only required a getKey method in the object, would that help you?

Yup absolutely. All I need is the ability to stream other PHP objects using any method possible 👍

@tonysm
Copy link
Collaborator

tonysm commented Jun 23, 2021

@stevebauman thanks for the contribution! I'll make some changes to the API, but I'll let you know when tagging it.

@tonysm tonysm merged commit 03032b2 into hotwired-laravel:main Jun 23, 2021
@tonysm
Copy link
Collaborator

tonysm commented Jun 23, 2021

@stevebauman I've changed a few things basically removed the need for the interface. All you need to do is implement the getKey() method that returns the ID of the resource in any class and things should work (see the changes here). Tagged version 0.10.0 with it. Please, let me know if that works for you. And thanks again for contributing! 👍🏼

@stevebauman
Copy link
Contributor Author

Ah this is perfect, thanks @tonysm! Even better that I don't have to implement the interface. 👍 This definitely works for me.

Happy to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants