Пример #1
0
 private function create()
 {
     $rootId = rand(100, 9999);
     $text = Pm\Text::create(['text' => 'Lorem ipsum lores']);
     $pm = Pm::create(['root_id' => $rootId, 'user_id' => $this->user->id, 'author_id' => $this->author->id, 'folder' => Pm::INBOX, 'text_id' => $text->id]);
     Pm::create(['root_id' => $rootId, 'user_id' => $this->author->id, 'author_id' => $this->user->id, 'folder' => Pm::SENTBOX, 'text_id' => $text->id]);
     return $pm;
 }
Пример #2
0
 /**
  * Submit a new message
  *
  * @param \Coyote\User $user
  * @param Request $request
  * @throws \Exception
  */
 public function submit(\Coyote\User $user, Request $request)
 {
     $rootId = $request->get('root_id', dechex(mt_rand(0, 0x7fffffff)));
     $author = $this->user->findByName($request->get('author'));
     if (!$author) {
         throw new \Exception('Can not get recipient ID.');
     }
     $text = Pm\Text::create(['text' => $request->get('text')]);
     $fill = ['root_id' => $rootId, 'text_id' => $text->id];
     // we need to create two records. one for recipient and one for message author
     $this->model->create($fill + ['user_id' => $author->id, 'author_id' => $user->id, 'folder' => Pm::INBOX]);
     $pm = $this->model->create($fill + ['user_id' => $user->id, 'author_id' => $author->id, 'folder' => Pm::SENTBOX]);
     return $pm;
 }