squire
squire copied to clipboard
Unable to locate Squire source for [App\Models\Country]
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.
Hey, I cannot replicate this. Please provide a repo where I can, and I will happily reopen this issue. Thanks!
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,
],
// ...
];
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.
I have the same issue
I have the same issue
@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.