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

Laravel resource convention #50

Closed
wants to merge 4 commits into from
Closed

Laravel resource convention #50

wants to merge 4 commits into from

Conversation

bilogic
Copy link
Contributor

@bilogic bilogic commented Jul 6, 2021

As discussed here #47
If accepted, next step can be to move the screenMatch macro into https://github.com/orchidsoftware/platform

@tabuna
Copy link
Member

tabuna commented Jul 6, 2021

I don't really like the recording and what it leads to. I expected that we would be fully compliant with a Laravel resource.
But with what we have, I'm not sure if we really need a new macro with an exact enumeration of methods. What will it give us?

As for the code. Then I think we can make a much nicer look:

Route::screen('/match', Example::class)
    ->methods('GET');

Route::screen('/match', Example::class)
    ->methods(['GET', 'POST']);

To do this, you need to create a class:

use Illuminate\Support\Arr;
use Illuminate\Support\HigherOrderTapProxy;

class ScreenRoute extends HigherOrderTapProxy
{
    /**
     * @param string|array $methods
     */
    public function methods($methods): self
    {
        $this->target->methods = Arr::wrap($methods);

        return $this;
    }
}

And in the platform macro, return it:

// ...

$route = $this->any($url.'/{method?}', [$screen, 'handle']);

$methods = $screen::getAvailableMethods();

if (! empty($methods)) {
    $route->where('method', implode('|', $methods));
}

return new ScreenRoute($route);

This will make it less painful to add things to the screen definition.

But I repeat that I completely do not understand what advantages we can get.
I expected in the issue that we change some of the names from:
/crud/view/{resource?}/{Id} to /crud/{resource?}/{Id}.

Maybe I don't understand you completely. Open to discussion

@bilogic
Copy link
Contributor Author

bilogic commented Jul 6, 2021

@tabuna I gave a reply here #47 (comment)

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants