lundi 15 août 2016

laravel 5.1- Retrieving single record from database table using eloquent

am trying to retreive data from my events table using the following approach $event = \App\Event::where('id','=',$eventid)->get(); I am expecting to retrieve only one record matching the eventid. When I dumped the value of $event following ouput is printed.

    object(Illuminate\Database\Eloquent\Collection)#560 (1) {
  ["items":protected]=>
  array(1) {
    [0]=>
    object(App\Event)#561 (24) {
      ["connection":protected]=>
      NULL
      ["table":protected]=>
      NULL
      ["primaryKey":protected]=>
      string(2) "id"
      ["keyType":protected]=>
      string(3) "int"
      ["perPage":protected]=>
      int(15)
      ["incrementing"]=>                                                              bool(true)
      ["timestamps"]=>
      bool(true)
      ["attributes":protected]=>                                                      array(7) {
        ["id"]=>
        int(4)
        ["name"]=>
        string(15) "Sandbox BizCase"
        ["user_id"]=>
        int(57)
        ["city_id"]=>
        int(1)
        ["created_at"]=>
        string(19) "2016-08-15 13:52:29"
        ["updated_at"]=>
        string(19) "2016-08-15 13:52:29"
        ["deleted_at"]=>
        NULL
      }
      ["original":protected]=>
      array(7) {
        ["id"]=>
        int(4)                                                                          ["name"]=>
        string(15) "Sandbox BizCase"
        ["user_id"]=>
        int(57)
        ["city_id"]=>
        int(1)
        ["created_at"]=>
        string(19) "2016-08-15 13:52:29"
        ["updated_at"]=>
        string(19) "2016-08-15 13:52:29"
        ["deleted_at"]=>
        NULL
      }
      ["relations":protected]=>
      array(0) {
      }
      ["hidden":protected]=>
      array(0) {
      }
      ["visible":protected]=>
      array(0) {
      }
      ["appends":protected]=>
      array(0) {
      }
      ["fillable":protected]=>
      array(0) {
      }
      ["guarded":protected]=>
      array(1) {
        [0]=>
        string(1) "*"
      }
      ["dates":protected]=>
      array(0) {
      }
      ["dateFormat":protected]=>
      NULL
      ["casts":protected]=>
      array(0) {
      }
      ["touches":protected]=>
      array(0) {
      }
      ["observables":protected]=>
      array(0) {
      }
      ["with":protected]=>
      array(0) {
      }
      ["morphClass":protected]=>
      NULL
      ["exists"]=>
      bool(true)
      ["wasRecentlyCreated"]=>
      bool(false)
    }
  }
}

Please tell me what is the method shall I use to read values of the record retrieved.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire