Laravel 5.4 mail markdown 2 button inline - laravel

I would like to know how to place the button next to each other.
Now it is on a separate line.
#component('mail::message')
Dear {{$vendor_name}}
Product {{$product_id}} : {{$product_name}} price id : {{$price_id}} will expire on {{$date_expire}}.
Please renew price.
#component('mail::button', ['url' => 'http://phuketjettour.com/', 'color' => 'green'])
Phuket Jet Tour
#endcomponent
#component('mail::button', ['url' => 'http://phuketjettour.com/s/vendors'])
Vendor submission
#endcomponent
Thanks,<br>
Phuket Jet Tour
#endcomponent

Dynamic number of inline buttons
For me the following worked to create 2, 3, 4 (dynamic number) of buttons inline in Laravel markdown mails:
1) Add a new directory for your custom component
First lets extend the mail configuration to include our new directory for components:
config/mail.php
<?php
// ...
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
resource_path('views/emails/components') // <-- This line was added
],
],
2) Create the new component for inline buttons
You need to create both, the HTML and the text version of the component. Otherwise you will get a InvalidArgumentException "View $name not found":
www/resources/views/emails/components/html/buttons.blade.php
This is the HTML file:
<table class="action" align="center" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td align="center">
<table border="0" cellpadding="0" cellspacing="0" role="presentation">
#if(null !== ($headline ?? null))
<tr><td><h2 style="text-align: center;">{{ $headline }}</h2></td></tr>
#endif
<tr>
<td>
#foreach($buttons as $button)
{!! $button['slot'] !!}
#endforeach
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
www/resources/views/emails/components/text/buttons.blade.php
This is the text file
#if(null !== ($headline ?? null))
{{ $headline }}
------------------------------
#endif
#foreach($buttons as $button)
{!! $button['slot'] !!}: {{ $button['url'] }}
#endforeach
3) Include the new component in your mails:
Now you can just include the component in your markdown emails like so:
Example with 2 inline buttons and a headline:
#component('mail::buttons', [
'headline' => 'Share link',
'buttons' => [
[
'url' => 'https://wa.me/?text=' . urlencode('Whatsapp text'),
'slot' => 'WhatsApp',
],[
'url' => 'https://t.me/share/url?text=' . urlencode('telegram text'),
'slot' => 'Telegram',
]
]
])
#endcomponent
Example with 3 inline buttons without a headline:
#component('mail::buttons', [
'buttons' => [
[
'url' => 'https://wa.me/?text=' . urlencode('Whatsapp text'),
'slot' => 'WhatsApp',
],[
'url' => 'https://t.me/share/url?text=' . urlencode('telegram text'),
'slot' => 'Telegram',
],[
'url' => 'https://twitter.com/intent/tweet?text=' . urlencode('Twitter text'),
'slot' => 'Twitter',
]
]
])
#endcomponent
Example with 3 inline buttons with different colours:
#component('mail::buttons', [
'buttons' => [
[
'url' => 'https://wa.me/?text=' . urlencode('Whatsapp text'),
'slot' => 'WhatsApp',
'color' => 'blue' // This is the default
],[
'url' => 'https://t.me/share/url?text=' . urlencode('telegram text'),
'slot' => 'Telegram',
'color' => 'green'
],[
'url' => 'https://twitter.com/intent/tweet?text=' . urlencode('Twitter text'),
'slot' => 'Twitter',
'color' => 'red'
]
]
])
#endcomponent

I have done it like this, ofcourse the css should be in a separated file
<style>
.email-row {
}
.email-col-2 {
width: 49%;
display: inline-block;
}
</style>
#component('mail::message')
<div class="email-row">
<div class="email-col-2">
#component('mail::button', ['url' => '453634', 'color' => 'light'])
btn1
#endcomponent
</div>
<div class="email-col-2">
#component('mail::button', ['url' => '123', 'color' => 'green'])
bnt2
#endcomponent
</div>
</div>
#endcomponent

When passing a variable to a blade template, use a single quote ( ' ) instead of a double quote ( " ).
$btn_style = " color: #FFF; border: 1px solid #FEFEFE; padding: 5px 30px;";
$buttons = '<span style="text-align: center; width: 100%; display: inline-block;">
Accept
Decline
</span>';
To render this code:
Edit your App\Mail
$this
->subject('Subject')
->markdown('emails.tempalte')
->with([
'buttons' => $buttons,
]);
Blade Template view\emails:
{!! $buttons !!}
Hope this helps.

you can put it in one <div>
For example:
<div class = "row>
your buttons here
</div>
If it doesn't help please share your code
Try this:
<span style="display: inline;">
#component('mail::button', ['url' => 'http://phuketjettour.com/', 'color' => 'green'])
Phuket Jet Tour
#endcomponent
#component('mail::button', ['url' => 'http://phuketjettour.com/s/vendors'])
Vendor submission
#endcomponent
</span>

It's just a work around. I've inspect the email from a laravel project.
try this in place of your component for button :
Phuket Jet Tour
SAMPLE !
it inlines your button. then just adjust other element. If you want to put the button on the markdown then you do like:
On your markdown:
$button1= " Phuket Jet Tour";
$button2 = "SAMPLE !";
$emailMarkdown = $this->markdown('your_email_template')
->subject('your_subject)
//you will define here the variables you need to pass in the template
->with([
'emailBody' => $emailBody,
'button_first' => $button1,
'button_second' => $button2,
]);
return $emailMarkdown;
then on the email template:
#component('mail::message')
Dear {{$vendor_name}}
Product {{$product_id}} : {{$product_name}} price id : {{$price_id}} will expire on {{$date_expire}}.
Please renew price.
{!!$button_first!!} {!!$button_second!!}
#endcomponent

To fix the issue, just place this code in email blade file:
<div style="text-align: center">
Cancel
Reschedule
Confirm
</div>

Related

Missing Keys: title

I installed Bagisto and everything run smoothly until I added Laravel AliExpress Dropshipping.
There's error :
Webkul\Ui\Exceptions\ActionKeyException
Missing Keys: title (View: /Applications/MAMP/htdocs/bagisto/packages/Webkul/Dropship/src/Resources/views/admin/products/index.blade.php)
What does Missing Keys: title means
#extends('admin::layouts.content')
#section('page_title')
{{ __('dropship::app.admin.products.title') }}
#stop
#section('content')
<h1>
{{ __('dropship::app.admin.products.title') }}
</h1>
<div class="page-action">
<button class="btn btn-lg btn-primary" style="display: none">
{{ __('dropship::app.admin.products.import-btn-title') }}
</button>
</div>
I had a similar problem with Bagisto Bulk Upload extension. To fix it I added the 'title' key to both addAction at extension's DataGrid class.
public function prepareActions() {
$this->addAction([
'type' => 'Edit',
'method' => 'GET', // use GET request only for redirect purposes
'route' => 'marketplace.bulkupload.profile.edit',
'icon' => 'icon pencil-lg-icon',
'title' => ''
]);
$this->addAction([
'type' => 'Delete',
'method' => 'GET', // use GET request only for redirect purposes
'route' => 'marketplace.bulkupload.profile.delete',
'icon' => 'icon trash-icon',
'title' => ''
]);
$this->enableAction = true;
}
Source

How to do Nesting of html elements in cakePHP 3 syntax?

I want to know that how to write the below given html code in cakePHP 3 syntax :-
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
<span class="sr-only">Toggle navigation</span>
</a>
you can simply put the span tag inside the html link this way
<?= $this->Html->link(
'<span class="sr-only">Toggle navigation</span>',
'#', [
'class' => "sidebar-toggle",
'data-toggle' => "push-menu",
'role' => "button",
'escape' => false
]); ?>
or you can use the tag method to create the span tag
<?= $this->Html->link(
$this->Html->tag('span', 'Toggle navigation', ['class'=>"sr-only"]),
'#', [
'class' => "sidebar-toggle",
'data-toggle' => "push-menu",
'role' => "button",
'escape' => false
]); ?>

Laravel blade, recursive view with php translated to blade

I have this recursive view with php, which is plain wrong so I have to translate this to blade, for recursive call for a view.
My php recursive code in (comments.blade.php):
<?php
tree($Comments, 0, 0);
$var = -1;
function tree($Comments, $parent_id = 0, $level=0, $c=0) {
global $var;
foreach($Comments as $Comment) {
if($Comment['parent_id'] == $parent_id) {
If ($level > $var) $var++; else {
for ($i = $var-$level+1; $i>0; $i--) { if ($c < 0) echo '</div> </div>'; else $c--; };
$var=$level;
};
echo '<div class="media">
<div class="media-left">
<a href="#">
<img class="media-object" src="..." alt="...">
</a>
</div>
<div class="media-body">
<h4 class="media-heading">Media heading</h4>';
tree($Comments, $Comment['id'], $level+1,$c);
}
};
};
?>
And that's what I am looking for(in comments.blade.php:
<div>
#include('recursive', ['comments' => $comments, 'parent_id' => 0, 'level' => 0, 'c' => 0])
</div>
The thing is I don't know how to translate all that variables in first snippet of code into blade, so to create Recursive.blade.php:
Edit 1:
Guys please help me, I worked 2 days on this damn algorithm and I am stuck once again in a problem even bigger then it was 2 days ago :(
For some people that doesn't understand why I am sticking with that code is because that code above is the algorithm for making the threaded comments like that on reddit, in the algorithm there is 2x echo, and a media class echo.
If i put 2x after the media class on 2 comments in a row, the next one comment will create with first one, comments with same parent_id, this means they are childs that belong to the same comment(parent before them), If the 2x div are not put then this means the next one comment after first is the child of the first and so on. This is my algorithm, i am doing this to translate to blade because I have some cheeky votes buttons which uses routes that i will integrate into recursive design, that's why i want to be translate to blade, but i don't know how. :(
Why would you call the recursively for generating the view, you can make an file name comment.blade.php and run a loop inside main blade file which will include the comment.blade.php and pass the comment object or array and then the comment.blade.php file will user the properties of that $comment object or array.
For example:
$Comments = [
[
'body' => 'First comment',
'name' => 'First Commentator'
],
[
'body' => 'Second comment',
'name' => 'Second Commentator'
],
[
'body' => 'Third comment',
'name' => 'Third Commentator'
],
[
'body' => 'Fourth comment',
'name' => 'Fourth Commentator'
],
[
'body' => 'Fifth comment',
'name' => 'Fifth Commentator'
],
[
'body' => 'Sixth comment',
'name' => 'Sixth Commentator'
],
];
and in your main blade file that can be index.blade.php or any other
#foreach($Comments as $Comment)
#include('comment',['comment'=>$comment])
#endforeach
comment.blade.php file would have
<div class="media">
<div class="media-left">
<a href="#">
<img class="media-object" src="..." alt="...">
</a>
</div>
<div class="media-body">
<h4 class="media-heading">Media heading</h4>
</div>
</div>
There is a automatic tool for get this job done. check out PHP2Blade
you can convert multiple files to blade syntax by runnig this command.
php php2blade <files directory> <optional output directory>

toggle an html section on laravel 4.2 when using return Redirect

In my view i have this section where a user can add a new record to the database but the laravel form is inside a section where it is hidden by default here is my code in my view
<section id="anCity" style="display:none">
{{ Form::open(array('url'=> 'addCty')) }}
<div class="form-group">
{{ Form::label('ncty', 'City Name: ') }} <span style="color:red"><i>{{ $errors->first('ncty', ':message') }}</i></span>
{{ Form::text('ncty', Input::old('ncty'), array('class' => 'form-control','placeholder' => 'Insert City Name')) }}
</div>
{{ Form::submit('Add new City', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
</section>
And inside my controller here is my code
$rules = array(
'ncty' => 'required|max:100|alpha_num'
);
$messages = array(
'ncty.required' => 'Please enter City Name.',
'ncty.max' => 'City Name can only have a maximum of 100 characters',
'ncty.alpha_num' => 'City Name can only contain alphanumeric characters'
);
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails())
{
return Redirect::to('lookup_board')
->withErrors($validator)
->withInput(Input::except('password'));
}
else
{
//insert new record
}
Is there a way to toggle the section on my view on the controller?
thanks
you can do it like:
<span class="#if($errors and $errors->has('ncty')) has-error #endif">{{ $errors->first('ncty') }}
I suppose you are using Twitter Bootstrap so it already has a class has-error for errors that you can use.
Replace your opening section tag with the following:
<section id="anCity"{{ ($errors->any() ? '' : ' style="display:none"') }}>

Add image to button Laravel 5

Hi my submit button is like this:
{!! Form::open([
'id' => 'form-id',
'method' => 'delete',
'action' => ['ToDoListController#delete', $task->id],
]) !!}
{!! Form::submit('Delete', [
'id' => 'my-id',
'name' => 'bt_add',
'image' => '../../images/delete.jpg',
]) !!}
{!! Form::close() !!}
I want to add image to my button but don't know how. Please help me.
Why not use a button?
<button type="submit" id="my-id" name="btn_add"><img src=""></button>
You can add a css class to your button and then define the image to be used in that class e.g.
{!! Form::submit('Delete', [
'id' => 'my-id',
'name' => 'bt_add',
'class' => 'bt_add',
]) !!}
In the css...
.bt_add {
background:url(/images/Btn.PNG) no-repeat;
width: 200px;
height: 100px;
border: none;
}
Sorry I haven't tested this (bit of a hurry) but this should give you the effect you want. See other posts on button images e.g. Setting an image button in CSS - image:active

Resources