讨论数量:
public function show(Topic $topic)
{
$categories = Category::all();
return view('topics.create_and_edit', compact('topic', 'categories'));
}
public function create(Topic $topic)
{
return view('topics.create_and_edit', compact('topic','categories'));
}
代码如上,是这里吗?求大神指点。
@Fykex 点击 话题后报错!求解。。
/home/vagrant/Code/larabbs/app/Http/Controllers/TopicsController.php
use App\Models\Topic;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\UserRequest;
use App\Http\Requests\TopicRequest;
use App\Models\Category;
use Auth;
class TopicsController extends Controller
{
public function __construct()
{
$this->middleware('auth', ['except' => ['index', 'show']]);
}
public function index(Topic $topic)
{
$categories = Category::all();
$topics = $topic->withOrder($request->order)->paginate(20);
return view('topics.index', compact('topics'));
}
public function show(Topic $topic)
{
$categories = Category::all();
return view('topics.create_and_edit', compact('topic', 'categories'));
}
public function create(Topic $topic)
{
$categories = Category::all();
return view('topics.create_and_edit', compact('topic','categories'));
}
public function store(TopicRequest $request, Topic $topic)
{
$topic->fill($request->all());
$topic->user_id = Auth::id();
$topic->save();
Arguments
"Undefined variable: request"


控制器如下
<?php
namespace App\Http\Controllers;
use App\Models\Topic;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\UserRequest;
use App\Http\Requests\TopicRequest;
use App\Models\Category;
use Auth;
class TopicsController extends Controller
{
public function __construct()
{
$this->middleware('auth', ['except' => ['index', 'show']]);
}
public function index(Topic $topic)
{
$categories = Category::all();
$topics = $topic->withOrder($request->order)->paginate(20);
return view('topics.index', compact('topics'));
}
public function show(Topic $topic)
{
$categories = Category::all();
return view('topics.create_and_edit', compact('topic', 'categories'));
}
@ayauper 错误很明显了,高亮的23行,$request不存在
需要将$request依赖注入到控制器中
public function index(Topic $topic,Request $request)
关于 LearnKu
@ayauper 错误很明显了,高亮的23行,$request不存在
需要将$request依赖注入到控制器中