How do i get primary Id on another table ??

Posted 8 months ago by Jaikangam

I am not able to get the primary ID, how do i do... need your help badly I have "saleregistrationmaster" table and "service" table

on the salesregistrationmaster table i have $table->increments('id'); $table->string('cefnumber')->nullable(); $table->string('customername',50); $table->text('install_address'); $table->text('correspondent_address')->nullable(); $table->string('mobile_number'); $table->string('alt_number')->nullable(); $table->string('landline_no')->nullable(); $table->string('email')->unique(); $table->date('dor'); $table->string('priority'); $table->string('remarks')->nullable();

and on the services table

Schema::create('services', function (Blueprint $table) { $table->increments('id'); $table->integer('sale_id')->unsigned(); $table->string('services'); $table->timestamps(); $table->foreign('sale_id') ->references('id') ->on('salesregistrationmasters') ->onUpdate('cascade')->onDelete('cascade'); }); ====================================== on my service model i use belongTo relation but doesnt work class Service extends Model { protected $casts = [ 'services' => 'array', ];

protected $fillable = [

public function salesregistration()
    return $this->belongsTo(Salesregistrationmaster::class);


When i insert form services i want to get the sale_id from the salesregistrationmaster table. How can i do it ??

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.