damian_nz - 2 months ago

Hi there, I have a stream in a custom module that has been in production for about a year. A new requirement has come up and I want to be able to sort them as you can with pages by dragging.

I have made a new migration and tried simply doing

protected $stream = [
    'slug' => 'filters',
    'sortable' => true
];

Unfortunately this didn't work.

Is it possible to make a stream sortable after the initial migration?

Then when it is working, how do I query to get it in the sorted order? Or will that happen automatically?

Thank you

Answer

ryanthompson - 2 months ago

I don't think that method of migration allows for updating it only defines the stream to use for subsequent assignments in the shorthand method. My suggestion when modifying fields / assignments / streams after they're created would be to use the normal up/down methods and the included repositories:

$stream = $this->streams()->findBySlugAndNamespace('foo', 'bar');
$stream->sortable = true;
$stream->save();

That will update the DB, update the models, etc.

ryanthompson - 2 months ago

If you are trying to simply make them sortable in a table - this is all you need. But you mention pages which are nested. So you would need to use the tree builder instead of the table builder in your controllers.

Again it'll sort by sort order by default assuming the migration was accurate but nested will require parent field to work properly in the tree builder.

damian_nz - 2 months ago

Thanks Ryan, so if that code is enough to make them sortable, any idea why it wouldn't be working? I have run the migration and tried a streams:refresh but no change, is there a value in the streams__streams table that should change?

ryanthompson - 2 months ago

Ya what’s your streams_streams table look like for the stream in question? Should have it’s aortable column true. Any options on your table builder that would be forcing any certain order otherwise?

damian_nz - 2 months ago

The streams entry had not updated through the migration. I can't see any reason why not so I have just manually updated the DB

ryanthompson - 2 months ago

I don't think that method of migration allows for updating it only defines the stream to use for subsequent assignments in the shorthand method. My suggestion when modifying fields / assignments / streams after they're created would be to use the normal up/down methods and the included repositories:

$stream = $this->streams()->findBySlugAndNamespace('foo', 'bar');
$stream->sortable = true;
$stream->save();

That will update the DB, update the models, etc.