Laravel Learning Management System

Hi, I'm following your tutorial vdeos to create a LMS in youtube https://youtube.com/playlist?list=PLgsruFcRiyk1W3vvSl3vvWJFU_iVHpJtv&si=uML2APc7uuhqEHON I'm having a problem when trying to setup a route with optional parameter, in this case 'course/{course}/episodes/{episode?}' if i'm trying to get 'course/1/episodes/1 it will return successfully but when i try to get 'course/1/episodes/' it will return 404 any idea how to fix this? thank you
YouTube
Let's Build A Course Website
A collection of live streams where we create a course website with Laravel, Livewire and Filament
2 Replies
tuto1902
tuto19022w ago
Can I see the handler of the route? (callback function or controller)
lazycoder
lazycoderOP2w ago
web.php Route::get('/courses/{course}/episodes/{episode?}', WatchEpisode::class)->name('courses.episodes.show'); WatchEpisode.php <?php namespace App\Livewire; use App\Models\Course; use App\Models\Episode; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Contracts\HasForms; use Filament\Infolists\Concerns\InteractsWithInfolists; use Filament\Infolists\Contracts\HasInfolists; use Filament\Infolists\Infolist; use Filament\Infolists; use Livewire\Component; class WatchEpisode extends Component implements HasInfolists, HasForms { use InteractsWithInfolists, InteractsWithForms; public Course $course; public Episode $currentEpisode; public function mount(Course $course, ?Episode $episode = null) { $this->course = $course; $this->currentEpisode = isset($episode->id) ? $episode : $course->episodes->first(); } public function episodeInfolist(Infolist $infolist): Infolist { return $infolist ->record($this->currentEpisode) ->schema([ \App\Infolists\Components\VideoPlayerEntry::make('vimeo_id') ->hiddenLabel(), Infolists\Components\TextEntry::make('overview') ->label('Overview'), Infolists\Components\RepeatableEntry::make('course.episodes') ->schema([ Infolists\Components\TextEntry::make('title') ->label('') ->icon('heroicon-o-play-circle'), Infolists\Components\TextEntry::make('formatted_duration') ->label('') ->icon('heroicon-o-clock'), ]), ]); } public function render() { return view('livewire.watch-episode'); } }

Did you find this page helpful?