Blade embedded components - laravel

In some applications, I have very small blade templates that I only use in one single template.
Unfortunately I still need to create a separated file such as:
Component jumbotron:
<div class="jumbotron">
<h1 class="display-4">{{ $title }}</h1>
{{ $slot }}
</div>
In my main component I then use:
#component('jumbotron', ['title' => 'Foo'])
Hello World!
#endcomponent
I would like to find a way to embed my component in my template such as:
#template('jumbotron')
<div class="jumbotron">
<h1 class="display-4">{{ $title }}</h1>
{{ $slot }}
</div>
#endtemplate
#component('jumbotron', ['title' => 'Foo'])
Hello World!
#endcomponent
I this somehow possible?

Related

How to get currencies from rest coutries API v3.1 using Laravel?

#foreach ($responseBody as $response)
<div class="row">
<div class="col-4">Official Name</div>
<div class="col-8">{{$response->name->official}}</div>
</div>
<div class="row">
<div class="col-4">Currencies</div>
<div class="col-8">{{ $response->currencies???? }}</div>
</div>
#endforeach
I using Laravel to consume API from https://restcountries.com/. I success to get Name of the country, but I still failed to get the currencies. The "SGD" code is different for each country.
How to get the name of currencies?
You should run another loop for the currencies:
#foreach($response->currencies as $id => $info)
<b>{{ $id }}</b>: {{ $info->name }} {{ $info->symbol }}
#endforeach

{!! Html::style('css/parsley.css') !!} NOT WORKING

I'm new to Laravel and I also understand that Laravel has stopped supporting Collective but I managed to still install the package into my Laravel 5.8 project.
Now my problem is, when I tried adding the line below, it does not work. When I inspect element, it's not showing in the head section of the page.
{!! Html::style('css/parsley.css') !!}
Do you think it has something to do with the fact that Laravel no longer supports Collective or I'm doing something wrong here?
Thank you so much for your help guys!
I also tried using
<link href="{{ asset('css/parsley.css') }}" rel="stylesheet">
BUT STILL NOT WORKING.
This is the code of the whole page I'm working on.
#extends('main')
#section('title', '| New Post')
#section('stylesheets')
{{-- {!! Html::style('css/parsley.css') !!} --}}
<link href="{{ asset('css/parsley.css') }}" rel="stylesheet">
#endsection
#section('content')
<div class="jumbotron">
<div class="container">
<h1 class="display-4">Create New Post</h1>
<p class="lead"></p>
<hr class="my-4">
<p>Fill out the fields to write your post.</p>
{{-- <a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a> --}}
</div>
</div>
<div class="container">
<div class="col-sm-12 col-md-12">
{!! Form::open(array('route' => 'posts.store', 'data-parsly-validate' => '')) !!}
{{ Form::label('title', 'Title:') }}
{{ Form::text('title', null, array('class' => 'form-control', 'required' => '')) }}
{{ Form::label('body', 'Body:') }}
{{ Form::textarea('body', null, array('class' => 'form-control', 'required' => '')) }}
{{ Form::submit('Create Post', array('class' => 'btn btn-success btn-lg btn-block mt-2')) }}
{!! Form::close() !!}
</div>
</div>
#endsection
#section('scripts')
{!! Html::script('js/parsley.min.js') !!}
#endsection
I expected the parsley.css and parsley.min.js be imported into the page but it didn't work.
How does your template looks like? Do you have a #yield('stylesheets') in your template?
Where is your parsley.css located?
I fixed the problem. I had to remove the Collective codes and back to basic to make it work.

Displaying A Laravel Collection in a blade template

I'm having issues displaying a collection in a blade template.
$comments = Comment::all();
return view('comments/index')->with(compact('comments'));
The code for the blade is:
#isset($comments)
#foreach($comments as $comment)
<div>
<p>
<{{ $comment->commentor }}
</p>
</div>
<hr>
#endforeach
#endisset
#empty($comments)
<div>
<p>There were no comments available.</p>
{{ $comments }}
</div>
#endempty
But not sure how to get the data to render in the template. It just renders a blankpage.
Use this instead :
$comments = Comment::all();
return view('comments.index')->with(compact('comments'));
Use dot notation to reference the view folder structure, view('comments.index'). This represents the file resources/views/comments/index.blade.php. Use this.
#forelse ($comments as $comment)
<div>
<p>
{{ $comment->commentor }}
</p>
</div>
<hr/>
#empty
<div>
<p>There were no comments available.</p>
</div>
#endforelse

Why do i have a form url point at thesame location but not at a specific file that will insert my data into database

My LoginUser.blade.php
<h1>Login</h1>
{{-- Form start comment --}}
{{ Form::open(array('url' => 'user/loginUser')) }}
<p>
{{ Form::label('email', 'E-Mail Address') }}
{{ Form::email('email', null, array("placeholder" => "Enter your email")) }}
</p>
<p>
{{ Form::label('password', 'Password') }}
{{ Form::password('password', array("placeholder"=>"Enter your password")) }}
</p>
<p>
{{ Form::submit('Sign In') }}
</p>
{{ Form::close() }}
{{-- Form end comment --}}
So my Question is why should my URL points to my current LoginUser.blade.php which contains the HTML forms?? Please am new to laravel am using laravel 5.2

Volt adding multiple class in view

I'm building a website with Volt 0.9 and I'm trying to customize my main.html regarding navigation.
Well, there is and if binding in the :Nav section to add a class. The problem is that I want to add another class with another if binding. I've tried to add a second if binding, but no luck, the are not rendered when I'm using a second if binding.
How can I do that ?
Here's the file :
<:Title>
{{ view main_path, "title", {controller_group: 'main'} }}
<:Body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<ul class="nav navbar-nav pull-left">
<:nav href="/">Hammicus</:nav>
<:nav href="/tv">HammicusTV</:nav>
<:nav href="/radio">HammicusRadio</:nav>
<:nav href="/contact">Contact</:nav>
</ul>
<:volt:notices />
{{ view main_path, 'body', {controller_group: 'main'} }}
</div>
</nav>
<footer class="footer">
<p>© Hammicus {{ Time.now.year }}</p>
</footer>
<:Nav>
<li class="{{ if active_tab? }}active{{ end }} {{ if attrs.href == "/" }}brand{{ end }}">
{{ yield }}
</li>
The problem seems to be the double quotes around the "/"
Replace them with single quotes (so they are properly nested) and it should work.
ie
class="{{ if active_tab? }}active{{ end }} {{ if attrs.href == '/' }}brand{{ end }}"

Resources