Skip to content

Instantly share code, notes, and snippets.

@moradi-morteza
Last active December 22, 2019 17:52
Show Gist options
  • Save moradi-morteza/b57500eb11b4b3a442211d74ebda6b19 to your computer and use it in GitHub Desktop.
Save moradi-morteza/b57500eb11b4b3a442211d74ebda6b19 to your computer and use it in GitHub Desktop.
[blade] #LaravelT
// in file template user
<html>
<body>
@yield('header')
@yield('content')
@yield('footer')
</body>
</html>
// then in your second file view-one.blade.php
@extends('template')
@section('header')
View one's header
@endsection
@section('content')
View one's content
@endsection
//-------------------------------------
// for run php code in blade use
@php(/*code*/) //or
@php @endphp
//----------------------------------
//@include is just like a basic PHP include, it includes a "partial" view into your view.
// you can say if isset(red) so show footer red
//example:
@include('foldername.filename')
@include('foldername.filename',[$message=>'salam'])
@includeWhen(/* condition */,'foldername.filename')
// for example
/* in main layout */ @includeWhen(empty($donotshowlist),'foldername.filename')
/* in wanted page define in top of page :*/ @php($donotshowlist=true)
//----------------Component-------------
<!-- /resources/views/alert.blade.php -->
@php $class = isset($class) ? $class : 'btn' @endphp // its the way of check if value exist or not
<div class="alert alert-danger">
{{ $message }}
</div>
// where you want to use
@component('alert',['message'=>' <Whoops! Something went wrong!'])@endcomponent
// another easy way is :
@component('alert')
@slot('messate')
<span> ops! there is some error</span>
@endslot
@slot('class','btn')
@endcomponent
// if else switch ------------------
@if(isset($data))
<span>list hast</span>
@else
<span>list nist</span>
@endif
//--------------
@switch($day)
@case(1)
شنبه
@break
...
// -----------
@for($i=0;$i<5;$i++)
{{$i}}
@endfor
//---------------------
@push('name')
@endpush
@stack('name')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment