-
-
Notifications
You must be signed in to change notification settings - Fork 541
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
[5.x] Ability to have a custom Entry class per collection #11203
base: 5.x
Are you sure you want to change the base?
Conversation
5815d24
to
438f396
Compare
This looks awesome! |
Requiring a collection in I wonder if So like... $entry = Entry::make(); // Statamic\Entries\Entry
$entry->locale('en'); // Statamic\Entries\Entry
$entry->collection('blog'); // App\Entries\BlogPost
$entry->slug('foo'); // App\Entries\BlogPost class Entry
{
public function collection($collection = null)
{
// ...
+ $custom = $collection->class();
+
+ if ($custom && ! $this instanceof $class) {
+ return app($custom)
+ ->slug($this->slug())
+ ->date($this->date())
+ ->etc();
+ }
return $this;
}
} |
Ya I like this, would mean I could revert all the test changes too, which I like. I'll keep hacking on this, thanks for your feedback |
fac18e7
to
032322a
Compare
Can you provide some more details about how this works in the PR description? |
I believe the gist is... Create a custom entry class: class BlogPost extends Entry
{
public function shareToSocials() {
//
}
} Use it in the collection: title: Blog
+class: App\BlogPost Now you can use your custom methods. $entry = Entry::find('blog-post-1'); // App\BlogPost
$entry->shareToSocials(); But only for that collection. $entry = Entry::find('page-1'); // Statamic\Entries\Entry
$entry->shareToSocials(); // MethodNotFoundException |
This is probably as close as I'll ever get to you letting me have a model per collection... |
(This is from @jasonvarga below)
Create a custom entry class:
Use it in the collection:
title: Blog +class: App\BlogPost
Now you can use your custom methods.
But only for that collection.