-2

Why using of @extends in PHP file (using of @ with any text or string)?

@extends('front.layouts.master')

@section('content')
    // ...
@endsection

And also tell me @if, @endif example for ifelse condition, I am lilbit confused about using of @ with any syntax or text,

Example code

 @if ($errors->has('firstname'))
                    <span class="help-block">
                      <strong>{{ $errors->first('firstname') }}</strong>
                    </span>
                    @endif
Shah Syed
  • 23
  • 7

1 Answers1

1

I suggest you read up on the official documentation: https://laravel.com/docs/5.6/blade It's easy to understand.

@extends allows you to create a blade file, that is going to be inside another blade:

main.blade.php

<html>
<head>
    <script src="path/to/script"></script>
    @yield('additional_scripts)
</head>
<body>
    <div>This is some text I want to be shown in multiple views</div>
    @yield('content')
</body>
</html>

sub.blade.php

@extends('main')

@section('additional_scripts')
    <script src="path/to/some/other/script/only/needed/here"></script>
@endsection

@section('content')
    <div>I want this to visible only in this view</div>
@endsection

About @if directive: I'm not sure what's not to understand here. Can you be more specific about what's confusing you?

@if(isset($variable))
    Output this text and this {{ $variable }}
@elseif(isset($anotherVariable))
    Output {{ $anotherVariable }}
@else
    Output just the text
@endif
Criss
  • 952
  • 5
  • 17