I want to have the same mechanism like this https://www.w3schools.com/html/default.asp but in laravel application
This is my code on routes/web.php
Route::get('tutorial', function(){
$tutorial = Tutorial::get();
return view('tutorial.index')->with('tutorial', $tutorial);
})->name('index-tutorial');
// Show one Tutorial by Id
Route::get('tutorial/{id}', function($id){
$tutorial = Tutorial::findOrFail($id);
return view('tutorial.show')->with('tutorial', $tutorial);
})->name('show-tutorial');
for my Blade template
tutorial/show.blade.php
<div class="container">
@foreach($tutorial as $tutorial)
<h1>{{$tutorial->title}}</h1>
<p>{{$tutorial->title_description}}</p>
<p>{{$tutorial->title_lesson}}</p>
<div class="btn-group btn-group-lg d-flex justify-content-end mb-3" role="group">
<form class="mx-3" action="{{route('delete-tutorial', $tutorial->id)}}" method="POST">
@csrf
@method('DELETE')
<button class="btn btn-danger" name="Delete">Delete</button>
</form>
<form action="{{route('edit-tutorial', $tutorial->id)}}" method="GET">
@csrf
<button class="btn btn-primary" name="Edit">Edit</button>
</form>
@endforeach
</div>
tutorial/index.blade.php
<main class="d-flex flex-nowrap">
<div class="d-flex flex-column flex-shrink-0 p-3 text-bg-dark"
style="width: 280px;">
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-
auto text-white text-decoration- none">
<svg class="bi pe-none me-2" width="40" height="32"><use
xlink:href="#bootstrap"></use></svg>
<span class="fs-4 text-white">MySql Lessons</span>
</a>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
@forelse($tutorial as $link)
<li class="nav-item">
<a href="{{route('show-tutorial', $link->id)}}" class="nav-
link">
<p class="text-white bg-dark">{{$link->title}}</p>
</a>
</li>
@empty
<p class="text-white bg-dark">No available lesson</p>
@endforelse
</ul>
</div>
I been researching a lot about having this mechanism
This one is different from other questions because i don’t use controllers for this
2
Answers
Instead of using route closures, I manage to convert them to a TutorialController
for the aside bar routes/web
layout/sidebar.blade.php
in my index.blade and show.blade you can add @include('layout.sidebar')
Have you tried using example tamplates from Bootstrap?
Check here https://getbootstrap.com/docs/5.3/examples/
it’s quite easy actually, you just need to copy the html code from bootstrap tamplate and tweak here and there. use
@include to add your desired components, @yield for your desired content page. and use @extends and @section inside your content pages.
roughly like this.
your main blade view
for your side bar you just need to put links for your desired page
in like this in your content pages
make use of the @include and @yield build in function. this way you’ll have a consistent navbar/sidebar but can changes the content within.
Hope this works for you 🙂