Closed sineld closed 5 years ago
Hi, I would need more information to understand the context. Could you provide me with the error message and stack trace? Thanks
Let me explain, when using Polymorhic relations, Laravel writes the whole Model with the namespace (App\User), but when we add the morphMap to AppServiceProvider like below:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Relations\Relation;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
//
}
public function boot()
{
Relation::morphMap([
'App\User',
]);
}
}
App\User becomes users and this occurs error below:
/Users/sineld/Code/laravel58/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php
public function getMorphClass()
{
$morphMap = Relation::morphMap();
if (! empty($morphMap) && in_array(static::class, $morphMap)) {
return array_search(static::class, $morphMap, true);
}
return static::class;
}
/**
* Create a new model instance for a related model.
*
* @param string $class
* @return mixed
*/
protected function newRelatedInstance($class)
{
return tap(new $class, function ($instance) {
if (! $instance->getConnectionName()) {
$instance->setConnection($this->connection);
}
});
}
/**
* Get all the loaded relations for the instance.
*
* @return array
*/
public function getRelations()
{
return $this->relations;
}
/**
* Get a specified relationship.
*
* @param string $relation
Arguments
"Class 'users' not found"
Please see images attached.
Indeed, it's a bug. It should be fixed with the latest commit on master
, please check.
By the way, you should do a full reindex after you've changed the morph map.
Yes, it's solved. Thanks. You may close the issue.
Thanks for your feedback. I've included the fix in the latest release.
Using,
in AppServiceProvider breaks application. I'm not sure if it is related to your package. Please check.