【发布时间】:2021-03-29 19:20:09
【问题描述】:
控制器
namespace App\Http\Controllers;
use App\Models\Article;
use Illuminate\Http\Request;
class ArticlesController extends Controller
{
public function show($id)
{
$article = Article::find($id);
return view('articles.show', ['article' => $article]);
}
}
路线
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Route::get('/about', function () {
return view('about', [
'articles' => App\Models\Article::take(3)->latest()->get()
]);
});
Route::get('/articles/{article}',
'App\Http\Controllers\ArticlesController@show');
show.blade.php
@extends ('layout')
@section ('content')
<div id="wrapper">
<div id="page" class="container">
<div id="content">
<div class="title">
<h3>{{ $article->title }}</h3>
<p>
<img src="/images/banner.jpg" alt=""
class="image image-full"/>
</p>
<p>{{ $article->body }}</p>
</div>
</div>
@endsection
错误
找不到类“App\Http\Controllers\Controller” http://localhost:8000/articles/2
我不确定我哪里出错了。我查看了 Laravel 8 中路由/控制器的文档,看起来我应该可以使用。
【问题讨论】:
标签: php laravel-routing laravel-8 laravel-controller