【发布时间】:2015-08-04 17:25:54
【问题描述】:
现在我不想在单击第一个主题时重定向到该主题网址。为此,我需要使用 DB:: 函数。我不想按给定的标题搜索,然后获取 id 等。例如我有帖子:
table name 与上图中的主题标题相同,因此我需要使用 DB::select 或 ::table 并按该名称搜索,然后打印结果。怎么做?
布局:
@extends('layouts.main')
@section('content')
<div class="panel panel-default">
<div class="panel-heading">Forum</div>
<div class="panel-body">
@forelse($forums as $forum)
@forelse($topics as $topic)
<a href="HERE MUST BE CODE TO POST FOR EXAMPLE http://example.com/topic/pirmas-atnaujinimas/64">{{ $topic->title }}</a><br>
@empty
<div class="alert alert-danger">Apgailėstaujame tačiau šis forumas yra tuščias!</div>
@endforelse
@empty
<div class="alert alert-danger">Apgailėstaujame tačiau forumas nerastas</div>
@endforelse
</div>
</div>
{!! $topics->render() !!}
@stop
提前致谢;(
更新 视图论坛控制器:
<?php
namespace App\Http\Controllers;
use DB;
use View;
class viewForum extends Controller
{
public function showForum($fname, $fid)
{
$forums = DB::table('forums')
->where('id', $fid)
->where('seo_name', $fname)
->select()
->get();
$topics = DB::table('topics')
->where('forum_id', $fid)
->select()
->paginate(1);
return View::make('forum', compact('forums', 'topics'));
}
}
【问题讨论】:
-
请同时贴出相关控制器的代码。