Home > Mobile >  Insert Failed : SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table
Insert Failed : SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table

Time:04-19

i need help!

I have a relation data like this: enter image description here

i want to pluck 2 columns from relation mail->mail meta.

so far i have tried this:

$data= \App\Models\MailRevisionHistory::with(['mail.mail_meta'])
    ->where('mail_id',$request->mail_id)
    ->first()
    ->pluck('mail.mail_meta.id','mail.mail_meta.key'); 

but i have an error like this:

{"status":1,"message":"Insert Failed : SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table \"mail_meta\"\nLINE 1: select \"mail\".\"mail_meta\".\"key\" from \"trx_mail_revision_hist...\n ^ (SQL: select \"mail\".\"mail_meta\".\"key\" from \"trx_mail_revision_history\")"

please correct where did i go wrong

CodePudding user response:

Please try this:

$data= \App\Models\MailRevisionHistory::with([
      'mail.mail_meta' => function($query) {
        $query->pluck('mail.mail_meta.id','mail.mail_meta.key');
      }
    ])
    ->where('mail_id',$request->mail_id)
    ->first(); 

CodePudding user response:

My suggested code: ‌

  1. use namespace :

    use \App\Models\MailRevisionHistory;

  2. code :

$data= MailRevisionHistory::query()->with([
    'mail.mail_meta' => function($query) {
        $query->pluck('mail.mail_meta.id','mail.mail_meta.key');
    }
])
    ->where('mail_id',$request->input('mail_id'))
    ->first();

CodePudding user response:

After trying many times I finally found the solution :

$data = \App\Models\MailRevisionHistory::with(['mail.mail_meta'])
    ->where('mail_id',$request->mail_id)
    ->first();

$data2 = $data->mail->mail_meta->pluck('id','key');

I hope this helps someone in the future.

  • Related