mardi 9 août 2016

Composer package - use custom model if exists

My apologies if this exists already but my search-fu can not find the answer.

I have a composer package, and want to use my model ONLY IF an existing model doesn't exist (or extend the custom model), but I can't seem to figure out how to specify the "use" command properly inside my composer model. Since I won't know the name of the "app" using the package, I can't extend it.

<?php

namespace MyComposer\Package\Models;

use Illuminate\Database\Eloquent\Model;

class MyPackageModel extends Model
{

If I put it as a config option, I can't use that in the extends i.e class MyPackageModel extends config('custom_model_name')

I had thought I should do the check in the ServiceProvider but I can't seem to find the right code to register the proper model name to use in there.

Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire