laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

[Lumen] Custom Morph Map Name Relation Not Working #1899

Closed frama21 closed 4 years ago

frama21 commented 4 years ago

i have a problem with polymorph relation in Lumen default polymorph name in database inserted like this App\Models\Comment but i want this polymorph name inserted like this Comment this my boot AppServiceProvider code

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Http\Resources\Json\Resource;
use Illuminate\Database\Eloquent\Relations\Relation;

class AppServiceProvider extends ServiceProvider
{

    public function register()
    {
        //
    }

    public function boot()
    {
        Relation::morphMap([
            'Comment'   => Comment::class,
        ]);

        Resource::withoutWrapping();
    }
}

when i use Laravel, this code work with inserted name 'Comment' but in Lumen this not working

i use lumen 6.0

if you have a suggest or a example code let me know

timrspratt commented 4 years ago

Is this an exact paste of your AppServiceProvider, because the import for App\Models\Comment isn't included?

Have you also registered the service provider in bootstrap/app.php:

$app->register(App\Providers\AppServiceProvider::class);
frama21 commented 4 years ago

it's fixed ! i change Comment::class to App\Models\Comment thanks for remind me