Component and Slot

1] Create one folder inside view and give a name e.g component.

2] Create file (questions-component.blade.php) inside component folder

resources
— views
— — component
— — — question-component.blade.php

3] code inside question-component.blade.php. Consider we are going to repeat this code over and over again in the project

//question-component.blade.php<div style="background: #cbcda8">
    <div><b>Question:</b>-{{$question}}</div>
    <div><b>Answer :</b>- {{$answer}}</div>
</div>
<div style="padding: 10px;"></div>

4] create another file where we can write code for display (index.blade.php)

@component('component.question-component')@slot('question')
        What is earth?
    @endslot@slot('answer')
        Earth is planet
    @endslot@endcomponent@component('component.question-component')@slot('question')
        What is Laravel?
    @endslot@slot('answer')
        Laravel is a web application framework with expressive, elegant syntax
    @endslot@endcomponent