当前位置: 首页>>代码示例>>PHP>>正文


PHP Event::firstOrNew方法代码示例

本文整理汇总了PHP中app\Event::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Event::firstOrNew方法的具体用法?PHP Event::firstOrNew怎么用?PHP Event::firstOrNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Event的用法示例。


在下文中一共展示了Event::firstOrNew方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createSpecialEvents

    private function createSpecialEvents()
    {
        //NSBreakfast May
        $nsBreakfastMay = Carbon::create(2016, 5, 6, 8, 0, 0, new \DateTimeZone('Australia/Melbourne'));
        $nsBreakfastMay->setTimezone(new \DateTimeZone('UTC'));
        // using slug as a unique string identifier
        $slug = Str::slug(Event::SPECIAL . " {$nsBreakfastMay}");
        $this->info("Special Event (NSBreakfast) {$nsBreakfastMay} UTC");
        $event = Event::firstOrNew(['slug' => $slug]);
        $event->type = Event::SPECIAL;
        $event->slug = $slug;
        $event->title = 'NSBreakfast';
        $event->subtitle = 'Informal and unstructured; Hang out, drink coffee, eat breakfast and chat iOS / OSX';
        $event->starts_at = $nsBreakfastMay;
        $event->ends_at = $nsBreakfastMay->copy()->addHours(2);
        $event->contact = 'https://twitter.com/nsbreakfast';
        $event->contact_name = 'Matt Delves';
        $event->location = '1000 £ Bend';
        $event->location_link = 'http://thousandpoundbend.com.au';
        $event->address_display = '361 Little Lonsdale St, Melbourne';
        $event->address = '361 Little Lonsdale St, Melbourne, VIC 3000';
        $event->lat = -37.811672;
        $event->lng = 144.959092;
        $event->save();
        //NSBreakfast June
        $nsBreakfastJune = Carbon::create(2016, 6, 3, 7, 30, 0, new \DateTimeZone('Australia/Melbourne'));
        $nsBreakfastJune->setTimezone(new \DateTimeZone('UTC'));
        $slug = Str::slug(Event::SPECIAL . " {$nsBreakfastJune}");
        $this->info("Special Event (NSBreakfast) {$nsBreakfastJune} UTC");
        $event = Event::firstOrNew(['slug' => $slug]);
        $event->type = Event::SPECIAL;
        $event->slug = $slug;
        $event->title = 'NSBreakfast';
        $event->subtitle = 'Informal and unstructured; Hang out, drink coffee, eat breakfast and chat iOS / OSX';
        $event->starts_at = $nsBreakfastJune;
        $event->ends_at = $nsBreakfastJune->copy()->addHours(2);
        $event->contact = 'https://twitter.com/nsbreakfast';
        $event->contact_name = 'Matt Delves';
        $event->location = 'Hash Specialty Coffee';
        $event->location_link = 'http://facebook.com/hashcoffeeroasters';
        $event->address_display = '113 Hardware St, Melbourne';
        $event->address = '113 Hardware St, Melbourne, VIC 3000';
        $event->lat = -37.8123025;
        $event->lng = 144.9605897;
        $event->save();
        //WWDC Event June 2016
        $wwdcEventJune2016 = Carbon::create(2016, 6, 16, 18, 30, 0, new \DateTimeZone('Australia/Melbourne'));
        $wwdcEventJune2016->setTimezone(new \DateTimeZone('UTC'));
        $slug = Str::slug(Event::SPECIAL . " {$wwdcEventJune2016}");
        $this->info("Special Event (WWDC) {$wwdcEventJune2016} UTC");
        $event = Event::firstOrNew(['slug' => $slug]);
        $event->type = Event::SPECIAL;
        $event->slug = $slug;
        $event->title = 'Cocoaheads WWDC Special Event';
        $event->subtitle = <<<'EOT'
We're going to start off with a special intro I'm calling 'The Keynote That Was' (TKTW) and we will then watch two 
to three WWDC sessions. Depending on what's available at the time, we might have a few options but the best ones will be
the State of the Union sessions that are usually presented on the Tuesday morning in San Francisco.
EOT;
        $event->starts_at = $wwdcEventJune2016;
        $event->ends_at = $wwdcEventJune2016->copy()->addHours(3);
        $event->location = 'Teamsquare';
        $event->location_link = 'https://teamsquare.co/contact';
        $event->address_display = 'Level 1, 520 Bourke Street, Melbourne';
        $event->address = 'Level 1, 520 Bourke Street, Melbourne VIC 3000';
        $event->lat = -37.8153744;
        $event->lng = 144.958427;
        $event->tickets = 'http://melbournecocoaheads-wwdc-2016.eventbrite.com.au';
        $event->contact = 'https://twitter.com/melbournecocoa';
        $event->contact_name = 'Jesse Collis';
        $event->save();
        $event->sponsors()->detach();
        $event->sponsors()->attach(Sponsor::where('name', '=', 'Teamsquare')->first());
        $event->sponsors()->attach(Sponsor::where('name', 'Odecee')->first());
    }
开发者ID:melbournecocoa,项目名称:website,代码行数:75,代码来源:GenerateYearlyEvents.php

示例2: handle

 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     if ($this->isSeeding) {
         $toTake = 200;
         // 200 societies
         $delay = 0;
         // Immediately
     } else {
         $toTake = 20;
         // 20 societies
         $delay = 600;
         // 10 Minutes
     }
     FacebookSession::setDefaultApplication(getenv('FB_ID'), getenv('FB_SECRET'));
     $session = FacebookSession::newAppSession();
     try {
         $session->validate();
     } catch (FacebookRequestException $ex) {
         // Session not valid, Graph API returned an exception with the reason.
         dd($ex);
     } catch (\Exception $ex) {
         // Graph API returned info, but it may mismatch the current app or have expired.
         dd($ex);
     }
     $store = \App\Setting::where('name', 'next_society')->first();
     $lastUpdated = $store->setting;
     // Get last society ID updated;
     $societies = \App\Society::where('id', '>', $lastUpdated)->take($toTake)->orderBy('id')->get();
     // Get Societies to query
     foreach ($societies as $society) {
         $request = new FacebookRequest($session, 'GET', '/' . $society->facebook_ref . '/events' . '?since=' . time() . '&fields=name,start_time,location,description,cover');
         try {
             $response = $request->execute();
         } catch (\Exception $ex) {
             continue;
             // TODO: Report errors back to us :)
         }
         $graphObject = $response->getGraphObject();
         $events = $graphObject->asArray();
         if (array_key_exists('data', $events)) {
             $events = $events['data'];
             foreach ($events as $fbEvent) {
                 $storedEvent = \App\Event::firstOrNew(['facebook_id' => $fbEvent->id]);
                 $storedEvent->society_id = $society->id;
                 $storedEvent->title = $fbEvent->name;
                 $storedEvent->time = $fbEvent->start_time;
                 if (array_key_exists("description", $fbEvent)) {
                     $storedEvent->description = $fbEvent->description;
                 }
                 if (array_key_exists("location", $fbEvent)) {
                     $storedEvent->location = $fbEvent->location;
                 }
                 if (array_key_exists("cover", $fbEvent)) {
                     $storedEvent->image = $fbEvent->cover->source;
                 }
                 $storedEvent->save();
             }
         }
     }
     if (count($societies) < $toTake) {
         $store->setting = 0;
     } else {
         $store->setting += $toTake;
     }
     $store->save();
     $job = (new \App\Jobs\UpdateEvents())->delay($delay);
     if (!$this->isSeeding) {
         $this->dispatch($job);
     }
 }
开发者ID:boregan,项目名称:lowdown,代码行数:75,代码来源:UpdateEvents.php


注:本文中的app\Event::firstOrNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。