@mehrdad70 You are not filtering the courses by category, what do you expect? How are your courses related to categories anyway? What do your tables and relationships look like?
Jan 26, 2021
8
Level 2
Display products of each category in laravel
Hi everyone When I click on a category I want it to go to the course list page and show the courses related to that category
header.blade.php
@foreach ($categories as $category)
<li class="{{count($category->subCategory) > 0 ? 'dropdown' : ''}}">
<a href="{{route('courses.list' , $category->name)}}">{{$category->name}}</a>
<ul class="dropdown-menu">
@foreach ($category->subCategory as $child)
<li class="{{count($child->subCategory) > 0 ? 'dropdown' : ''}}">
<a href="{{route('courses.list' , $child->name)}}">{{$child->name}}</a>
@include('front.categories.child' , ['child' => $child])
</li>
@endforeach
</ul>
</li>
@endforeach
web.php
Route::get('/courses/list' , 'FrontController@courseList')->name('courses.list');
public function courseList()
{
$courses = Course::filter()->where('status' , Course::STATUS_ACCEPT)->latest()->paginate(10);
$categories = Category::all();
$teachers = User::all();
return view('front.courses.all-courses.all-course' , compact('courses' , 'categories' , 'teachers'));
}
course-list.blade.php
@forelse ($courses as $course)
<div class="col-4 col-md-6 col-12">
<div class="box">
<a href="{{$course->path()}}">
<img class="card-img-top" src="{{'/storage/' . $course->banner->files['600']}}" alt="Card image cap">
</a>
<div class="box-body">
<div class="text-left">
<h4 class="box-title"><a href="{{$course->path()}}">{{$course->limitCharTitle()}}</a></h4>
<p>{!! $course->limitCharBody()!!}</p>
<div class="row">
<p class="mb-10 text-light font-size-12"><i class="fa fa-graduation-cap mr-5"></i>{{$course->teacher->fullName ?? ''}}</p>
<p class="mb-10 text-light font-size-12" style="margin-left: 30px"><b class="badge badge-info">{{$course->getFreeOrCash()}}</b><b class="text-danger"> : قیمت</b></p>
</div>
<div class="row">
<a href="{{$course->path()}}" class="btn btn-outline btn-primary btn-sm">جزئیات دوره</a>
<span class="btn btn-outline btn-info btn-sm" style="margin-left: 10px">{{$course->formatTime()}} : زمان دوره</span>
</div>
</div>
</div>
</div>
</div>
@empty
<div class="alert alert-danger">
<b>دوره ای یافت نشد</b>
</div>
@endforelse
I have a button on the main page with a list of all courses
Which when I click on it applies the path, method and blade I mentioned above
The URL is the same
localhost: 8000/courses/list
Now I want it to change when I click on each category, but go to the same course list page and show the courses related to that category
localhost:8000/courses/list?category = laravel
Please or to participate in this conversation.