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

How to run a closure in formatter method? #1

Open
phuclh opened this issue Aug 23, 2019 · 1 comment
Open

How to run a closure in formatter method? #1

phuclh opened this issue Aug 23, 2019 · 1 comment

Comments

@phuclh
Copy link

phuclh commented Aug 23, 2019

I have a function to convert minutes to hour format: 1 hour 25 minutes

<?php

function convertToHoursMins($time, $format = '%02d:%02d') {
    if ($time < 1) {
        return;
    }
    $hours = floor($time / 60);
    $minutes = ($time % 60);
    return sprintf($format, $hours, $minutes);
}

echo convertToHoursMins(250, '%02d hours %02d minutes'); // should output 4 hours 17 minutes

How can I pass above function to formatter method to display in the slider label?

Thank you

@RobertBoes
Copy link
Owner

The way this package currently works, it's not really possible. The data is sent 'raw' to the frontend, by Laravel Nova. There is an option to change the "display template", you can append an percentage sign for example. There's currently no way to transformer the data, but I'm open to pull requests! I've written this when Nova was just released, don't know if there was (or is now) an option to transform the data server side. I could add an extra meta field, which accepts a value or closure and use that for displaying the value. But I'll have to look into that

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

No branches or pull requests

2 participants