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

Permit all type of data to be checked if empty #1

Merged
merged 1 commit into from
Jun 9, 2017

Conversation

mathieutu
Copy link
Contributor

For example, our LengthAwarePaginator (paginate() method) are throwing an error if they are empty.

You could also check if $data is an instance of Arrayable at the start, and convert it in array to avoid all theses problems and work with arrays in all the methods:

        if ($data instanceof Arrayable) {
            $data = $data->toArray();
        }

        if ($this->dataIsEmpty($data)) {
            return $this->make('No Content', 204);
        }
...

    protected function dataIsEmpty($data)
    {
        return empty($data);
    }

@coveralls
Copy link

coveralls commented Oct 28, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 0764fec on mathieutu:master into 45ab0b3 on neoxia:master.

@alexandre-butynski
Copy link
Contributor

Both methods are ok. I have no preference between them, your proposal is fine !

The only thing that could be done to complete this is to remove the dependency to the Laravel Collection class. It should be Arrayable instead.

@mathieutu mathieutu merged commit 2e45c5d into neoxia:master Jun 9, 2017
emilianosuarez added a commit to moovaio/laravel-csv-response that referenced this pull request Jan 25, 2023
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

Successfully merging this pull request may close these issues.

None yet

3 participants