Escape VueJS data binding syntax in Laravel Blade? - laravel

Laravel templating language Blade and VueJS data binding syntax are very similar.
How can I escape VueJS data binding syntax when in a *.blade.php file?
Example:
<div>
<!-- Want it with VueJS -->
{{ selectedQuestionDesc }}
</div>
<div>
<!-- Want it with Laravel Blade -->
{{ $selectedQuestionDesc }}
</div>

While asking the question I discovered that you can escape Laravel's Blade by prepending an # sign before the double brackets {{}} or the {!! !!} html rendering brackets.
So here is the answer:
<div>
<!-- HTML rendering with VueJS -->
#{{ selectedQuestionDesc }}
<!-- Data binding with VueJS -->
#{{ selectedQuestionDesc }}
</div>
<div>
<!-- HTML with Laravel Blade -->
{!! $selectedQuestionDesc !!}
<!-- Variable binding with Laravel Blade -->
{{ $selectedQuestionDesc }}
</div>

In order to output real HTML, you will need to use the v-html directive:
<p>Using v-html directive: <span v-html="rawHtml"></span></p>

Related

Remove header from laravel markdown template

I'm trying to remove the header part from laravel's markdown template but it's not working, I published the files into my vendor folder and all.
This is my message component:
#component('mail::layout')
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
#isset($subcopy)
#slot('subcopy')
#component('mail::subcopy')
{{ $subcopy }}
#endcomponent
#endslot
#endisset
{{-- Footer --}}
#slot('footer')
#component('mail::footer')
© {{ date('Y') }} {{ env('APP_NAME') }}.
#endcomponent
#endslot
#endcomponent
And my layout file:
{!! strip_tags($slot) !!}
#isset($subcopy)
{!! strip_tags($subcopy) !!}
#endisset
{!! strip_tags($footer) !!}
Any help?
Also, is it possible to make my own markdown template without using default layout? I tried adding laravel markdown components directly into my mail blade.php files but everything lookied like trash and uncentered.
Thanks in advance.
Using change mark down template
You need to fire php artisan vendor:publish --tag=laravel-mail command on project root using terminal
After executed above command, generate some blade file on below path: resources/views/vendor/mail/html
Remove code from header.blade.php.
Using custom mail template
Also you can send mail using custom mail template. see below code.
Mail::send([YOUR TEMPLATE], [DATA], function ($m) use ($user) {
$m->from('[FROM_MAIL]',[FROM_NAME]);
$m->to([TO_EMAIL])->subject([SUBJECT]);
});

the PUT method does not send messages

if necessary, I will also put the controller in check although it seems to
me that something is wrong with the method because on the output it shows me a "no message" error and nothing more
is on a piece of my view and the PUT method
{!! Form::model($cattle_inventory, array('route'=>
['cattle_inventories.update',$cattle_inventory->id,'method'=>'PUT']))!!}
<div class="form-group">
{!! Form::label('cow_name','Podaj Nazwę krowy') !!}
{!! Form::text('cow_name',null, ['class'=>'form-control']) !!}
</div>
Route
Route::resource('cattle_inventories','Cattle_inventoryController')->middleware('verified');
The documentation states:
HTML forms do not support PUT, PATCH or DELETE actions. So, when defining PUT, PATCH or DELETE routes that are called from an HTML form, you will need to add a hidden _method field to the form. The value sent with the _method field will be used as the HTTP request method:
<form action="/foo/bar" method="POST">
#method('PUT')
#csrf
</form>
Hence you need to adjust your form as such. #method('PUT') simply generates the following HTML:
<input type="hidden" name="_method" value="PUT">
You can try this with Laravel collective
{!! Form::open(['route'=>['your.route', $id]]) !!}
// laravel <=5.5
{!! Form::hidden('_method', 'PUT') !!} //or {{ method_field('PUT') }}
//laravel >=5.6
#method('PUT')
{!! Form::close() !!}
Laravel collective Form model binding
{{ Form::model($cattle_inventory, ['route' => ['cattle_inventories.update', $cattle_inventory->id]]) }}

Blade embedded components

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?

Laravel 5 Blade Mystery

I am having a curious blade problem.
I have an edit blade that is rendering, but not with the master blade. Debugbar shows that both views (master and delete) are being shown. They are not!
Other blades used in conjunction with master all work. I tried duplicating those blades and inserting the specific data to no avail.
I have cleared history in the browser and done php artisan cache:clear. Nothing.
Master Blade is working for all other renderings. Here is detail:
<div class="intro">
<section>
#yield('intro')
</section>
</div>
This blade works and is rendered with the master:
#extends('layouts.master')
#section('title')
Your Profile
#stop
#section('head')
#stop
#section('intro')
<div class="output">
<h2>Your Pets</h2>
<div>
</div>
#if(sizeof($pets) == 0)
No pets
#else
#foreach($pets as $pet)
<div class="p1">
<h3>{{ $pet->petName }}</h3>
<p><img src='{{ $pet->photo }}' width="200px" height="200px"></p>
<p>{{ $pet->breed }}</p>
<a href='/profile/edit/{{$pet->id}}'>Edit</a> |
<a href='/profile/confirm-delete/{{$pet->id}}'>Delete</a>
</div>
#endforeach
#endif
</div>
#stop
#section('body')
#stop
This blade renders but with no master! Debugbar says that both views are rendering. Ha!
#extends('layouts.master')
#section('title')
Delete Your Pet
#stop
#section('head')
#stop
#section('intro')
<div class="output">
<h1>Delete Pet</h1>
<p>
Are you sure you want to delete <em>{{$pets->petName}}</em>?
</p>
<p>
<a href='/profile/delete/{{$pets->id}}'>Yes...</a>
</p>
</div>
#stop
#section('body')
#stop
Anyone seen this?
#stop was removed from the docs as of 5.1, so I would guess it is probably no longer supported. Use #endsection instead.
http://laravel.com/docs/5.1/blade

Laravel: Getting plain text while using Form class

I am a beginner of laravel. I have just installed "illuminate/html": "~5.0" with the help of link http://www.ekoim.com/blog/fix-class-form-html-not-found-laravel-5/
Now when I tried using of {{ Form::open() }} {{ Form::close() }} in view file. It is returning form in plain text format to browser.
<form method="POST" action="http://project.dev" accept-charset="UTF-8"><input name="_token" type="hidden" value="qNbi3DD1YGQncOv3PRBWl1l6BxVViWZnleVAmniS"></form>
I am attaching screenshot here.
Is there anything I forgot to do in order to this code to work?
Unlike Laravel 4, in Laravel 5 the content between {{ }} is now escaped by default. To output unescaped content you need to use {!! !!}. So in your case:
{!! Form::open() !!} {!! Form::close() !!}
Read more in the Laravel Templates Docs.

Resources