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

Unable to locate Squire source for [App\Models\Country] #16

Open
ShamarKellman opened this issue Mar 22, 2021 · 6 comments
Open

Unable to locate Squire source for [App\Models\Country] #16

ShamarKellman opened this issue Mar 22, 2021 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@ShamarKellman
Copy link

Describe the bug
Unable to find source when using extended Country model.

To reproduce

namespace App\Models;

use Squire\Models\Country as SquireCountry;

class Country extends SquireCountry
{
    public function users()
    {
        return $this->hasMany(User::class);
    }
}

Call

App\Models\Country::all();

Expected behavior
Expected to show all countries

Context

  • Squire version: 2.0.6
  • Laravel version: 8.33.1
  • Server OS: osx - laravel valet
  • PHP version: 8.0

Additional details
Add any other details about the problem here.

@ShamarKellman ShamarKellman added the bug Something isn't working label Mar 22, 2021
@danharrin
Copy link
Member

Hey, I cannot replicate this. Please provide a repo where I can, and I will happily reopen this issue. Thanks!

@aminetiyal
Copy link

I face the same issue as @ShamarKellman and I solved it by re-registering sources:

  • SquireServiceProvider.php
<?php

namespace App\Providers;

use App\Models\Country;
use Squire\Repository;
use Illuminate\Support\ServiceProvider;

class SquireServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Repository::registerSource(Country::class, 'ar', resource_path('/squire-data/countries-ar.csv'));
        Repository::registerSource(Country::class, 'fr', base_path('/vendor/squirephp/countries-fr/resources/data.csv'));
        Repository::registerSource(Country::class, 'en', base_path('/vendor/squirephp/countries-en/resources/data.csv'));
    }
}

and

  • register the service provider in config/app.php:
<?php

return [
    // ...
    'providers' => [
        // ...
        App\Providers\SquireServiceProvider::class,
    ],
    // ...
];

@danharrin
Copy link
Member

Ah interesting. I see why this is a bug now. Because the sources are registered to the base class and not the original class, it can't find them. I'm going to think of a good way to fix this.

@danharrin danharrin reopened this Oct 20, 2021
@a21ns1g4ts
Copy link

I have the same issue

1 similar comment
@AlexanderFalkenberg
Copy link

I have the same issue

@aidan-casey
Copy link
Contributor

@danharrin - Probably the easiest way to come about this is to refactor the models to require a static getSourceKey() method which is used to register it.

We could always check if the name is an existing class and then recurse its parents, that just seems like too much going on though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants