0
Я пытаюсь выяснить, как я могу применять различные стили CSS для моей страницы index.blade.php в зависимости от того, активна ли категория $.laravel css styling на основе оператора if
I.e Если в URL-адресе нет категории, указанной в 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);
}
}
index.blade.php
@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 Был один ') 'отсутствует. Я исправил его –