public function getCanReplyAttribute() { if (Entrust::can('replyToAllThreads')) { return true; } if (Auth::check() && Auth::user()->isConfirmed() && $this->locked == 0 && $this->channel->can(6, Auth::user())) { return true; } return false; }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return Entrust::can('accessAdminPanel'); }
public function authorOrAdminPermissioinRequire($author_id) { if (!Entrust::can('manage_topics') && $author_id != Auth::id()) { dd('您没有这个权限'); } }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return Entrust::can('accessAdminPanel') && Entrust::can('closeReports'); }
/** * Search in the database for certain items * * @param SearchRequest $request * @return mixed */ public function search(SearchRequest $request) { $searchQuery = $request->has('query') ? $request->input('query') : Input::old('query'); $resultsArray = []; // Search in the topics table $topics = $this->topic->where('title', 'like', '%' . $searchQuery . '%')->get(); foreach ($topics as $topicResult) { $resultsArray[] = $topicResult; } // Search in the users table $users = $this->user->where('name', 'like', '%' . $searchQuery . '%')->get(); foreach ($users as $userResult) { $resultsArray[] = $userResult; } // Search in the posts table $posts = $this->post->where('content', 'like', '%' . $searchQuery . '%')->get(); foreach ($posts as $postResult) { $resultsArray[] = $postResult; } // Search for reports $reports = $this->report->where('reason', 'like', '%' . $searchQuery . '%')->get(); foreach ($reports as $reportResult) { $resultsArray[] = $reportResult; } // Search for conversations $conversations = $this->conversation->where('subject', 'like', '%' . $searchQuery . '%')->get(); foreach ($conversations as $conv) { $resultsArray[] = $conv; } $results = Collection::make($resultsArray); $results = $results->filter(function ($item) { if ($item instanceof User) { return !$item->isBanned() and $item->isConfirmed(); } if ($item instanceof Topic) { return $item->canView; } if ($item instanceof Post) { return $item->topic != null && $item->topic->canView; } if ($item instanceof Report) { return Entrust::can('viewReports'); } if ($item instanceof Conversation) { if (!Auth::check()) { return false; } try { $item->getParticipantFromUser(Auth::id()); return true; } catch (ModelNotFoundException $ex) { return false; } } }); $results = $results->sortBy(function ($item) { if ($item instanceof Conversation) { return 'conversation_' . mb_strtolower($item->subject); } if ($item instanceof User) { return 'user_' . mb_strtolower($item->name); } if ($item instanceof Topic) { return sprintf('topic_%-12s%s', mb_strtolower($item->title), $item->posts()->count()); } if ($item instanceof Post) { if ($item->updated_at == null || $item->updated_at->toDateTimeString() <= $item->created_at->toDateTimeString()) { return sprintf('post_%s%-12s', mb_strtolower($item->content), $item->created_at); } return sprintf('post_%s%-12s', mb_strtolower($item->content), $item->updated_at); } if ($item instanceof Report) { return sprintf('report_%-12s', mb_strtolower($item->reason)); } }); return view('core.search.search', compact('results', 'searchQuery')); }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $topic = $this->route()->getParameter('topic'); return Entrust::can('moderateThreads') && Entrust::can('unlockThreads') && $topic->canView; }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return Entrust::can('create_news_posts'); }
/** * Can this post be deleted by the current user? * * @return boolean */ public function getCanDeleteAttribute() { if (!Auth::check()) { return false; } return $this->user->isUser(Auth::user()) || Entrust::can('deleteAllPosts'); }