Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kayatech's avatar

insert get id

$i=1;

     $page = page::create([
        'title'=> $request->title,
        'discretion'=> $this->is_null($request->discretion,$request->title),
        'keyword'=>$this->is_null($request->keyword,$request->title),
        'position'=> $this->is_null($request->position,'2'),
        'status'=> $this->is_null($request->status,'0'),
        'pageindex'=> $this->is_null($request->pageindex,'0'),
        'parents'=> $this->is_null($request->parents,'0'),
        'pagetitle'=> $request->pagetitle,
        'pageurl'=> $this->call_url($request->pageurl)          
    ]);
   dd($page->id); // this function working 

  

    $Pangecontents = Pangecontents::create([
        'content'=> $request->content,                      
        'pages_id'=> $page->id,   // here can't work                    
        'orderby'=> '12'                   
    ]);

  $page->content=$Pangecontents;
    
    return response()->json($page,201);
0 likes
5 replies
RamjithAp's avatar

If the codes are in the same function it should work as it is.

Otherwise replace this line

 dd($page->id);  

with this

$page = Page::find($page->id);
kayatech's avatar

dd($page->id); this coed working good, next table insert $page->id

same code can't work

RamjithAp's avatar

Check this model Pangecontents has pages_id in the fillable array. Because page id available there but problem is it's not inserting properly.

1 like

Please or to participate in this conversation.