- Create a new
app/Statamic
folder. - Inside it, create two files:
EntryRepository.php
Entry.php
- For both of the two files, copy the contents from the relevant files in this Gist.
- Then, in your
app/Providers/AppServiceProvider.php
file, inside it'sboot
method, add theStatamic::repository
bit. - Run
composer dump-autoload
- You should see the
-
-
Save duncanmcclean/f68c25b58db5141f9c7ca9d09cf4a25f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
use Statamic\Statamic; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
// Statamic::script('app', 'cp'); | |
// Statamic::style('app', 'cp'); | |
// Add this bit... start | |
Statamic::repository( | |
\Statamic\Contracts\Entries\EntryRepository::class, | |
\App\Statamic\EntryRepository::class | |
); | |
// End | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Statamic; | |
class Entry extends \Statamic\Entries\Entry | |
{ | |
public function shallowAugmentedArrayKeys() | |
{ | |
// Note: we've added `price` here. Feel free to add any other fields you like. | |
return ['id', 'title', 'url', 'permalink', 'api_url', 'price']; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Statamic; | |
use Statamic\Contracts\Entries\Entry; | |
use Statamic\Contracts\Entries\QueryBuilder; | |
use Statamic\Stache\Query\EntryQueryBuilder; | |
class EntryRepository extends \Statamic\Stache\Repositories\EntryRepository | |
{ | |
public static function bindings(): array | |
{ | |
return [ | |
Entry::class => \App\Statamic\Entry::class, | |
QueryBuilder::class => EntryQueryBuilder::class, | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment