Passing the data to another method from the result of one method.

Posted 1 year ago by shashank313

The following is the output of tinker :-

PHP Deprecated:  Non-static method Illuminate\Support\Collection::all() should not be called statically on line 1
>>> user::find(85)->member
=> Illuminate\Database\Eloquent\Collection {#871
     all: [
       App\event {#883
         id: 71,
         eventtype_id: 2,
         event_name: "Steuber LLC",
         event_start_time: "2018-01-05 23:42:29",
         event_end_time: "2018-02-19 10:36:10",
         event_country: "Ut perspiciatis.",
         event_venue: "Nobis aut illo.",
         event_city: "Aut facilis quidem.",
         event_video_link: "https://www.heller.in/architecto-nihil-qui-et-praesentium-delectus-tenetur",
         event_website: "trantow.in",
         event_thumbnail_photo: "Sed ut necessitatibus accusamus numquam non sed.",
         event_banner_photo: "Occaecati autem enim dolore voluptas est autem.",
         event_status: 1,
         event_security_option: 0,
         event_has_sub_event: 1,
         user_id: 21,
         event_is_active: 1,
         created_at: "2018-04-09 18:38:34",
         updated_at: "2018-04-09 18:38:34",
         event_description: null,
         pivot: Illuminate\Database\Eloquent\Relations\Pivot {#886
           user_id: 85,
           event_id: 71,
           created_at: null,
           updated_at: null,
         },
       },
       App\event {#884
         id: 140,
         eventtype_id: 6,
         event_name: "White Group",
         event_start_time: "2017-12-14 02:43:46",
         event_end_time: "2018-02-12 21:47:53",
         event_country: "Maxime nihil.",
         event_venue: "Magnam facere.",
         event_city: "Officia quasi quo.",
         event_video_link: "http://steuber.com/eum-nobis-fugit-quaerat-sit-sit-qui-eveniet-non.html",
         event_website: "medhurst.com",
         event_thumbnail_photo: "Voluptatem quis sunt sunt fugit.",
         event_banner_photo: "Veritatis ab ab libero dolore in fugit.",
         event_status: 1,
         event_security_option: 1,
         event_has_sub_event: 0,
         user_id: 71,
         event_is_active: 1,
         created_at: "2018-04-09 18:38:38",
         updated_at: "2018-04-09 18:38:38",
         event_description: null,
         pivot: Illuminate\Database\Eloquent\Relations\Pivot {#880
           user_id: 85,
           event_id: 140,
           created_at: null,
           updated_at: null,
         },
       },
       App\event {#887
         id: 87,
         eventtype_id: 4,
         event_name: "Champlin-Medhurst",
         event_start_time: "2017-11-12 20:28:14",
         event_end_time: "2018-03-22 16:48:08",
         event_country: "Odit odit sapiente.",
         event_venue: "Numquam odit ipsam.",
         event_city: "Reiciendis sed nisi.",
         event_video_link: "http://rempel.com/placeat-aut-fugit-debitis-ipsa-quidem-aut-adipisci",
         event_website: "sauer.com",
         event_thumbnail_photo: "Ipsum nostrum ipsam dignissimos occaecati.",
         event_banner_photo: "Sequi autem error nihil.",
         event_status: 0,
         event_security_option: 0,
         event_has_sub_event: 1,
         user_id: 2,
         event_is_active: 0,
         created_at: "2018-04-09 18:38:35",
         updated_at: "2018-04-09 18:38:35",
         event_description: null,
         pivot: Illuminate\Database\Eloquent\Relations\Pivot {#882
           user_id: 85,
           event_id: 87,
           created_at: null,
           updated_at: null,
         },
       },
     ],
   }

It says that the userid 85 is the member in 3 events. Now in the event model, I have one to many relationship between event model and announcement model. So how should I fetch the all the announcements of all the events in which an user is a member?

I have tried this but there's an error :-

>>> user::find(85)->member()->announcements
PHP Notice:  Undefined property: Illuminate\Database\Eloquent\Relations\BelongsToMany::$announcements on line 1

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