0
$ 카테고리가 활성 상태인지 여부에 따라 다른 CSS 스타일을 index.blade.php 페이지에 적용 할 수있는 방법을 파악하려고합니다.if 문을 기반으로 한 laravel CSS 스타일링
e.e URL에 카테고리가 지정되지 않은 경우 이미지가 작아지고 URL에 카테고리가있는 경우 이미지가 커집니다.
Route.php 당신은 변경할 수 있습니다
Route::get('blog/{category}', ['as' => 'blog.category', 'uses' => '[email protected]']);
blogcontroller.php
public function getCategory($category = null)
{
// get all the blog stuff from database
// if a category was passed, use that
// if no category, get all posts
if ($category)
$posts = Post::where(function($query) use($category){
$query->where('category','=', $category);
}) ->get();
else
$posts = Post::all();
// show the view with blog posts (app/views/blog.blade.php)
return View::make('blog.index')
->with('posts', $posts);
}
}
@foreach ($posts as $post)
<h2>{{ $post->id }}</h2>
<h2>{{ $post->img }}</h2>
<p>{{ $post->name }}</p>
<p>{{ $post->category }}</p>
@endforeach
덕분에, 나는이 시도했지만, 예상치 못한 구문 오류가있다 ''기대 '('. (is_null ($ category) –
@tomharrison 누락되었습니다 ')'가 있습니다. 나는 그것을 바로 잡았다. –