Blade Templates for Frontend

Author: Al-mamun Sarkar Date: 2020-07-09 04:31:11

এই লেসনে আমরা দেখবো লারাভেল এ কিভাবে Blade Templates ব্যবহার করে Frontend ম্যানেজ করতে হয়।Blade Templates ব্যবহার করে কিভাবে If-else condition, for while foreach loop etc নিয়ে কাজ করতে হয়। 

 

layouts/app.blade.php

<!DOCTYPE html>
<html>
<head>
	<title> @yield('title', 'This is default title') </title>
	<link rel="stylesheet" type="text/css" href="{{ asset('bootstrap/css/bootstrap.min.css') }}">
	<link rel="stylesheet" type="text/css" href="{{ asset('css/style.css') }}">
</head>
<body>

	<div class="header">
		<h1>This is new header</h1>
	</div>

	@section('sidebar')
		<h2> This is sidebar </h2>
	@show

	@yield('content')

	<div class="footer" style="margin-top: 30px;">
		This is footer
	</div>

	<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/main.js"></script>
</body>
</html>

user/index.blade.php:

@extends('layouts.app')

@section('title', 'This is users page')

@section('content')
 <h2> Users page </h2>

@if($users)
	 {{ $users[0]->email }} 
@else
	<h2> No users found </h2>	 
@endif


@if(count($users) == 1) 
	<h2> Only one user found </h2>
@elseif(count($users) > 1)
	<h2> More than one user found </h2>
@else
	<h2> No users found </h2>	
@endif

@stop

 

post/index.blade.php:

@extends('layouts.app')

@section('title', 'This is posts page')

@section('sidebar')
	@parent
	hello sidebar	
@endsection

@section('content')
	<h1> All Posts </h1>

	
	@foreach($posts as $post)
		<div class="post">
			<h2>{{ $post->title }} </h2>
			<p> {{ $post->description }} </p>
		</div>
	@endforeach
	

	<h2> For Ealse </h2>
	@forelse ($posts as $post)
		<div class="post">
			<h2>{{ $post->title }} </h2>
			<p> {{ $post->description }} </p>
		</div>
	@empty
		<h2> No post fund </h2>
	@endforelse


@endsection