Back

the morphOne relation always return null


im setting up a One To One (Polymorphic) like this

My Models:

namespace App;
use Illuminate\Database\Eloquent\Model;
class Payement extends Model{
    protected $table = 'payements';
    protected  $primaryKey = 'id';
    protected $morphClass = 'App\Payement';
    public function payementable(){
        return $this->morphTo();
    }}

class Recu extends Model{
    protected $table = 'recus';
    protected  $primaryKey = 'id';  
    public function payement(){
        return $this->morphOne('App\Payement', 'payementable');
    }}

My Tables Schemas

Schema::create('recus', function (Blueprint $table) {
            $table->bigIncrements('id');
        });
Schema::create('payements', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('numero')->unique();
            $table->bigInteger('payementable_id');
            $table->string('payementable_type');
            $table->timestamps();
        });

the problem is this is working

App\Payement::find(1)->payementable; 

this is not

App\Recu::find(1)->payement;

Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us