@shyann
In Laravel, you can display related tables by using Eloquent relationships in your models. Here's a step-by-step guide to displaying related tables:
Example code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// User Model class User extends Model { public function posts() { return $this->hasMany(Post::class); } } // Post Model class Post extends Model { public function user() { return $this->belongsTo(User::class); } } |
1 2 3 4 5 |
// Controller $users = User::with('posts')->get(); return view('users.index', compact('users')); |
1 2 3 4 5 6 7 8 9 |
<!-- users.index.blade.php --> @foreach($users as $user) <h2>{{ $user->name }}</h2> <ul> @foreach($user->posts as $post) <li>{{ $post->title }}</li> @endforeach </ul> @endforeach |
This will display a list of users along with their related posts. Remember to replace the model and relationship names with your actual models and relationships in your application.