Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

By default, Eloquent will assume you’re using admin_id instead of penulis on the artikel table.

See the docs on Relationships:

class Phone extends Eloquent {

    public function user()
    {
        return $this->belongsTo('User', 'local_key', 'parent_key');
    }

}

Note that you have a local_key and parent_key, so your local_key would be penulis.

But in most situations I’d recommend you change your names so the defaults work.

Last updated 1 year ago.
0

thomasedwards said:

By default, Eloquent will assume you’re using admin_id instead of penulis on the artikel table.

See the docs on Relationships:

class Phone extends Eloquent {

   public function user()
   {
       return $this->belongsTo('User', 'local_key', 'parent_key');
   }

}

Note that you have a local_key and parent_key, so your local_key would be penulis.

But in most situations I’d recommend you change your names so the defaults work.

yes i already change it into admin_id

but it not working to, i try to

{{ dd(DB::getQueryLog()) }}

and i got this array

array(3) {
  [0]=>
  array(3) {
    ["query"]=>
    string(23) "select * from `Artikel`"
    ["bindings"]=>
    array(0) {
    }
    ["time"]=>
    float(1.71)
  }
  [1]=>
  array(3) {
    ["query"]=>
    string(69) "select * from `kategori_artikel` where `kategori_artikel`.`id` in (?)"
    ["bindings"]=>
    array(1) {
      [0]=>
      int(0)
    }
    ["time"]=>
    float(0.83)
  }
  [2]=>
  array(3) {
    ["query"]=>
    string(62) "select * from `Admin` where `Admin`.`id` in (?, ?, ?, ?, ?, ?)"
    ["bindings"]=>
    array(6) {
      [0]=>
      int(2)
      [1]=>
      int(5)
      [2]=>
      int(6)
      [3]=>
      int(7)
      [4]=>
      int(8)
      [5]=>
      int(4)
    }
    ["time"]=>
    float(0.93)
  }
}

and i also doing

dd($artikels = Artikel::with(['kategoriartikel','admin'])->get());

and getting

" ["kategori_artikel_id"]=> int(19) ["admin_id"]=> int(2) ["status"]=> int(1) ["gambar"]=> string(21) "wallpaper-2692643.jpg" ["pilihan"]=> int(1) ["created_at"]=> string(19) "2014-10-07 12:04:14" ["updated_at"]=> string(19) "2014-10-12 09:26:24" } ["relations":protected]=> array(2) { ["kategoriartikel"]=> NULL ["admin"]=> NULL } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } ["dates":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["morphClass":protected]=> NULL ["exists"]=> bool(true) } [1]=> object(Artikel)#305 (20) { ["table":protected]=> string(7) "Artikel" ["fillable":protected]=> array(7) { [0]=> string(5) "judul" [1]=> string(7) "content" [2]=> string(8) "kategori" [3]=> string(6) "status" [4]=> string(6) "gambar" [5]=> string(7) "pilihan" [6]=> string(7) "penulis" } ["connection":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(10) { ["id"]=> int(2) ["judul"]=> string(40) "Odio sed perspiciatis nihil rem aperiam." ["content"]=> string(1010) "
White Rabbit, trotting slowly back again, and said, very gravely, 'I think, you ought to have got in as well,' the Hatter added as an explanation. 'Oh, you're sure to happen,' she said this, she noticed that they could not join the dance. '"What matters it how far we go?" his scaly friend replied. "There is another shore, you know, as we were. My notion was that it made no mark; but he could go. Alice took up the little door into that lovely garden. First, however, she waited patiently. 'Once,' said the King, who had meanwhile been examining the roses. 'Off with her head!' Those whom she sentenced were taken into custody by the way of expressing yourself.' The baby grunted again, and all dripping wet, cross, and uncomfortable. The first thing she heard the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT-POCKET, and looked at her, and the second thing is to find her in a languid, sleepy voice. 'Who are YOU?' said the Caterpillar. Here was another long passage, and the blades of.

if you read carefully there will be

 { ["kategoriartikel"]=> NULL ["admin"]=> NULL } 

well is it supposed to be NULL?

Last updated 1 year ago.
0

thomasedwards said:

By default, Eloquent will assume you’re using admin_id instead of penulis on the artikel table.

See the docs on Relationships:

class Phone extends Eloquent {

   public function user()
   {
       return $this->belongsTo('User', 'local_key', 'parent_key');
   }

}

Note that you have a local_key and parent_key, so your local_key would be penulis.

But in most situations I’d recommend you change your names so the defaults work.

okay after checking multiple times i find out that there is some typo(lower case and upper case hahaha) for my function

so overall thank you for helping me out :D

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

t0n1zz t0n1zz Joined 8 Oct 2014

Moderators

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

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.