因此,我尝试了来自互联网的示例并编辑了此问题,因此想从名为{{1}的数据库的title
表中的特定ID中选择descrIption
和posts
列},以便它可以与我的引导程序集成。
我正在使用laravel
以下是我的引导程序中的welcome.blade.php视图中的几行
laravel
这是我尝试的PostController
<div class="blog-thumb">
<img src="asset/img/blog/1.jpg" alt="">
</div>
@foreach($posts1 as $post)
<h3>{{ $post->title }}</h3>
<p>{!! \Illuminate\Support\Str::words($post->description, 50, '...') !!}</p>
@endforeach
</div>
<div class="blog-thumb">
<img src="asset/img/blog/2.jpg" alt="">
</div>
@foreach($posts2 as $post)
<h3>{{ $post->title }}</h3>
<p>{!! \Illuminate\Support\Str::words($post->description, 50, '...') !!}</p>
@endforeach
</div>
这是路线
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Post;
class PostController extends Controller
{
public function getIndex1() {
$posts1 = Post::find(1);
}
public function getIndex2() {
$posts2 = Post::find(2);
}
public function getIndex3() {
$posts3 = Post::find(3);
}
但现在只显示白页
答案 0 :(得分:0)
您可以尝试以Folloe的路线
Route::resource('posts','PostsController');
如果要获取特定ID的数据,请使用
public function getIndex($id){
$uniquePost = Post::findOrFail($id);
}
并使用视图对其进行压缩。