本文整理汇总了PHP中Chat::user方法的典型用法代码示例。如果您正苦于以下问题:PHP Chat::user方法的具体用法?PHP Chat::user怎么用?PHP Chat::user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chat
的用法示例。
在下文中一共展示了Chat::user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$chat = new Chat();
//Validation
$rules = array('users' => 'required', 'subject' => 'required', 'text' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('/community/chats/create')->withInput()->withErrors($validator);
}
$chat->subject = Input::get('subject');
$chat->last_reply = date("Y-m-d H:i:s");
$chat->save();
$chat->user()->attach(Auth::user()->id);
foreach (Input::get('users') as $id) {
$chat->user()->attach($id);
}
$reply = new Reply();
$reply->text = Input::get('text');
$reply->chat_id = $chat->id;
$reply->user_id = Auth::user()->id;
$reply->save();
//Set up notifications for this chat
foreach ($chat->user->all() as $user) {
$reply->notification()->save($user);
}
$notification = Notification::where('user_id', '=', Auth::user()->id)->where('reply_id', '=', $reply->id)->firstOrFail();
$notification->has_read = 1;
$notification->save();
return Redirect::to('/community/chats')->with('flash_chat', 'Your chat has been sent')->with('alert_class', 'alert-success');
}