本文整理汇总了PHP中app\Topic::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Topic::with方法的具体用法?PHP Topic::with怎么用?PHP Topic::with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Topic
的用法示例。
在下文中一共展示了Topic::with方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$topics = Topic::with('user')->orderBy('created_at', 'desc')->paginate(10);
$data = $topics->map(function ($item, $key) {
$item->postsCount;
return $item;
});
return response()->json(['topics' => $data])->header('X-Page-Total', ceil($topics->total() / 10))->header('X-Page', $topics->currentPage());
}
示例2: show
/**
* Show the topic
*
* @param Request $request
* @return Response
*/
public function show(Request $request, $id)
{
$topic = App\Topic::with('comment', 'comment.user')->where('id', $id)->first();
if (empty($topic) || $topic->status == -1) {
if (Auth::guest() || !Auth::user()->is_admin()) {
return view('errors.topic404');
}
}
return view('topic.show', ['topic' => $topic]);
}
示例3: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
if (Auth::check()) {
$actu = Actualite::orderBy('id', 'desc')->first();
$topics = Topic::with('posts')->orderBy('created_at', 'desc')->take(5)->get();
//$postPerTopic =
$userLevel = $this::checkLevel();
return view('index', ['topics' => $topics, 'actu' => $actu, 'level' => $userLevel]);
} else {
return view('index');
}
}
示例4: index
/**
* List all of the topics from a given board
*
* @return \Illuminate\Request
*/
public function index()
{
$topics = Topic::with('topic_id', 'user_id');
return view('topics.index', compact('topics'));
}
示例5: delete_topic
public function delete_topic($id)
{
$topic = Topic::with('comments')->find($id);
if (Auth::user()->id == $topic->user_id) {
$topic->active = 0;
$topic->save();
foreach ($topic->comments as $comment) {
$comment->active = 0;
$comment->save();
}
}
return redirect('home');
}
示例6: forSubject
/**
* Get all of the topics for a given subject.
*
* @param Subject $subject
* @return Collection
*/
public function forSubject($subject_id)
{
return Topic::with('knowledgeunits')->where('topics.subject_id', $subject_id)->orderBy('created_at', 'asc')->get();
}
示例7: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//$topics = Topic::paginate($this->nbrPerPage);
$topics = Topic::with('user', 'posts')->orderBy('created_at', 'desc')->get();
return view('forum.index', ['topics' => $topics]);
}