Have you seen our video tutorials? Check 'em out!

Best approach creating featured projects on homepage

william - 3 months ago

Looking for the best approach here.

Scenario: You have a homepage, and you have a section where you got featured projects. These project blocks should have a regular text editor field as well as an image field.

Requirements: You should be able to add, remove and unpublish projects. Once you do, it should be reflected on the homepage.

Optional Requirement Be able to order the featured projects.

Question Is the best approach to create a post category, and then create posts and only get posts of that category? Or do i build something custom for it?

william - 3 months ago

Or, instead of posts - Create child pages to loop over?

ryanthompson - 3 months ago

I would use Streams if you have access to it - or create a super quick module. It'll take maybe 10 minutes your first time. Then you can assign a multiple relationship to your page and just loop over that like this:

{% for project in page.projects %}
    {{ project.title }}
{% endfor %}

ryanthompson - 3 months ago

One of the guys in Slack recently posted this discussion I had with him to help another newcomer develop a module in minutes: http://laravel.io/bin/PXam8

william - 3 months ago

Thanks. It actually took me 30 minutes. But the reason was i had a quick look at your video and didn't read this thread. And in your video you reference the fields with dots and not underscore. And since i was sleepwalking it took a while for me to realise that:)

But yes, dead simple ( esp if you have laravel experience ).

I am gonna figure out the next step now. I am sure ill find the answer in the documentation, or in your screencast (https://www.youtube.com/watch?v=Sq_7QKAMg14). But i thought i would help the community and other newcomers out by extending this thread.

Add on scenario:

  • I have launched a website using this project module.
  • After a year, my client comes back. He would like to also add a quote markdown field.

So ill likely need to create a new migration. Once done ill post back.

william - 3 months ago

I had a little problem getting this at first. But once i did, it was just as simple as anything else.

If you are looking for a solution yourself, basically what i did was:

1) Create a migration by :

# Projects is my slug and namespace for this modle
php artisan make:migration add_your_field_to_your_table --addon=projects

2) Set up your migration file a little different from using laravel (if you come from working within that, as i do), see below.

## The constructor
public function __construct()
    {
        $this->fields      = app('Anomaly\Streams\Platform\Field\Contract\FieldRepositoryInterface');
        $this->streams     = app('Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface');
        $this->assignments = app('Anomaly\Streams\Platform\Assignment\Contract\AssignmentRepositoryInterface');
    }

   public function up()
    {
        // Get your stream
        $stream = $this->streams->findBySlugAndNamespace('projects', 'projects');

        $field = $this->fields->create(
            [
                'slug'   => 'head',
                'type'   => 'anomaly.field_type.editor'
            ]
        );

        $this->assignments->create(
            [
                'field'  => $field,
                'stream' => $stream
            ]
        );


    }

3) Obviously you need to add a down method as well. Finally migrate it.

php artisan migrate --addon=projects

Since i am a newbie on pyro. Maybe there some improvements to be made. Appreciate any suggestion!

Best,
/w