How can use a data from angular in blade form? - php

I need use angulaar data like parameter in a Blade form, but i donĀ“t know how to do it
This is my code
Sorry for my English
<tr ng-repeat="data in datos">
<td>{{data.PAGO}}</td>
<td>{{data.AUTORIZACION}}</td>
<td>{{data.FECHAYHORA}}</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>{!! Form::open(['route'=>array('movimientosC.destroy',//I need angular data here//),'method'=>'DELETE']) !!}
<input type="hidden" name="accion" value="1"><div class="container">{!!Form::submit('Cancelar',['class'=>'btn btn-danger btn-xs']);!!}
</div>{!! Form::close() !!}</li>
</ul>
</div>
</td>
</tr>

You can either change angular brackets through use of $interpolateProvider:
angular.module('myApp', []).config(function($interpolateProvider){
$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
});
Or you can change laravel blade tags:
Blade::setContentTags('<%', '%>');
Blade::setEscapedContentTags('<%%', '%%>');

You can do this in blade by using the syntax #{{ data.PAGO }}. The # tells blade it should render that as text.

Related

I want to disable the delete post button inside in post foreach blade.. Laravel

I want to disable the delete post button inside in post foreach blade laravel . where post has created_at in database , i want the " delete post button" get disable after 15 days
i tried with some javascript tutorials but i couldn't achieve that thing
Can anyone please help me.it would be much appreciated if you could help me
thanks in adavance
<table id="" class="table ">
<thead>
<tr class="data-item master">
<th>Name</th>
<th>post</th>
<th>about</th>
<th>image</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
#foreach($data as $d)
<tr>
<td>{{$d->name}}</td>
<td>{{$d->postbody}}</td>
<td>{{$d->about}}</td>
<td>{{url($d->image)}}</td>;
<td><a href="{{ URL::to('edit/product/'.$d->id) }} "
class="btn btn-sm btn-info" title="edit">
<i class="fa fa-edit">edit post</i></a>
</td>
<td><a href="{{ URL::to('delete/product/'.$d->id) }} "
class="btn btn-sm btn-info" title="delete">
<i class="fa fa-trash"></i>delete post</a>
</td>
</tr>
#endforeach
</tbody>
</table>
You can not disable an anchor tag but you can change the URL to # as dummy url
#if(\Carbon\Carbon::parse($d->created_at)->addDays(15) < \Carbon\Carbon::now())
<a href="#"
class="btn btn-sm btn-info" title="delete">
<i class="fa fa-trash"></i>delete post</a>
#else
<a href="{{ URL::to('delete/product/'.$d->id) }}"
class="btn btn-sm btn-info" title="delete">
<i class="fa fa-trash"></i>delete post</a>
#endif
It's simple use and conditional statement on the disable attribute.
Something like This
<button class="anyClass" {{ Carbon::addDays(15)->greaterThan($post->created_at) ? 'disable' : ' }}>Delete</button>
I think something like this will work

Display Selected Option (different href) in Dropdown Title

Im working on my Laravel project, and i wanna make some filter buttons for my data table.
Those buttons look like this : https://i.stack.imgur.com/Swpbw.png
I want to display the selected option in dropdown title. For example, the Author title should be changed to any others name like Admin or User etc... after selecting the option from the dropdown button.
Author Dropdown Button (original) :
<div class="dropdown">
<button class="btn btn-outline-dark btn-sm dropdown-toggle mr-2" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Author
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
#foreach($users as $user)
<a class="dropdown-item" href="/posts?user_id={{$user->id}}">
{{ $user->name }}
</a>
#endforeach
</div>
</div>
I found some solutions, they all look like this :
$(".dropdown-menu").on('click', 'a', function(){
$(".btn:first-child").text($(this).text());
$(".btn:first-child").val($(this).text());
});
But the problem is :
The solution above only works if the href (url) from dropdown-menu is fixed (href="#").
In my project, those dropdowns have different href, so the title can only be changed for a short moment after clicked, then back to default after the url changed.
I think we need to catch the url then make some conditions to display the correct title.
For example, my Category filter only have 3 fixed options so i can do it like this.
Category Dropdown Button :
#php
$request = Request::getRequestUri();
#endphp
<div class="dropdown">
<button class="btn btn-outline-dark btn-sm dropdown-toggle mr-2" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
#switch(true)
#case(strstr($request, 'category_id=1'))
Pc
#break
#case(strstr($request, 'category_id=2'))
Console
#break
#case(strstr($request, 'category_id=3'))
Handheld
#break
#default
Category
#endswitch
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="{{strstr($request, 'category_id=1') ? 'dropdown-item active' : 'dropdown-item'}}" href="/posts?category_id=1">
Pc
</a>
<a class="{{strstr($request, 'category_id=2') ? 'dropdown-item active' : 'dropdown-item'}}" href="/posts?category_id=2">
Console
</a>
<a class="{{strstr($request, 'category_id=3') ? 'dropdown-item active' : 'dropdown-item'}}" href="/posts?category_id=3">
Handheld
</a>
</div>
</div>
Meanwhile, i have a foreach loop in the Author filter, cause the number of users is not fixed. So i cannot use the same code like i did with Category.
I had tried this but it just doesn't work.
Author Dropdown Button (not working) :
<div class="dropdown">
<button class="btn btn-outline-dark btn-sm dropdown-toggle mr-2" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
#if($request == '/posts' OR strstr($request, 'posts?page='))
Author
#else
#foreach($users as $user)
#if(strstr($request, 'user_id={{$user->id}}'))
{{ $user->name }}
#endif
#endforeach
#endif
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
#foreach($users as $user)
<a class="dropdown-item" href="/posts?user_id={{$user->id}}">
{{ $user->name }}
</a>
#endforeach
</div>
</div>
It cannot display the user name on title when clicked (blank result).
I also tried this one, but not working either.
#foreach($users as $user)
#if($request == "/posts?user_id={{$user->id}}"))
{{ $user->name }}
#endif
#endforeach
Please help guys !
you still can use the JS solution by preventing the redirection of the link
$(".dropdown-menu").on('click', 'a', function(event){
event.preventDefault();
event.stopPropagation();
$(".btn:first-child").text($(this).text());
$(".btn:first-child").val($(this).text());
});
I've found the solution.
The if condition (inside the foreach) is right, but somehow it doesn't work in blade template.
So, just put it in the php section.
Author Dropdown Button (working) :
<div class="dropdown">
<button class="btn btn-outline-dark btn-sm dropdown-toggle mr-2" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
#if($request == '/posts'
OR strstr($request, 'posts?search=')
OR strstr($request, 'posts?page='))
Author
#else
#foreach($users as $user)
#php
if(strstr($request, 'user_id='.$user->id)){
echo $user->name;
}
#endphp
#endforeach
#endif
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
#foreach($users as $user)
<a class="dropdown-item" href="/posts?user_id={{$user->id}}">
{{ $user->name }}
</a>
#endforeach
</div>
</div>

laravel - if else loop not working proper

I'm trying to write an if-else loop: if there is an embed saved in the database it should display a calendar, if not it should display a button saying "add new calendar/add new embed", but it's not working. I can't figure out why. When there is an embed saved in the database it displays the embed but, if there isn't an embed it doesn't display the button to add a new calendar/embed:
Blade view:
#if (empty($calendars))
#else
<h4>No calendar settings</h4><br>
<a href="{{ route('calendarsettings.create')}}">
<button class="btn btn-success btn-cons m-b-10" type="button">
<i class="fa fa-cloud-upload"></i>
<span class="bold">Add embed</span>
</button>
</a>
#endif
#foreach($calendars as $calendar)
{{ $calendar->embed }}
#endforeach
Controller:
public function kalendarz() {
$calendars = Calendar::with('users')->where('user_id', Auth::user()->id)->get();
return view('kalendarz',['calendars'=>$calendars]);
}
In Laravel 5.4, I would probably use the #unless blade directive, that will show the block, unless a condition is met. What the following code would acheive is "show the entries if we have some, and show the button unless we have some entries".
#if($calendar)
// show entries
#endif
#unless(empty($calendars))
// show a button to add a new one
#endunless
It kind of is the same "logic" as with an else, but somehow I think it's more clear and easy to read than an #else statement, and make it separate from the if.
The correct syntax is:
#if(empty($calendars))
<h4>No calendar settings</h4></br>
<a href="{{ route('calendarsettings.create')}}">
<button class="btn btn-success btn-cons m-b-10" type="button"><i class="fa fa-cloud-upload"></i> <span class="bold">Add embed</span></button>
</a>
#else
#foreach($calendars as $calendar)
{{ $calendar->embed }}
#endforeach
#endif
empty() functions empty the variable $calendars, so try using count()
#if(count($calendars) > 0)
<h4>No calendar settings</h4></br>
<a href="{{ route('calendarsettings.create')}}">
<button class="btn btn-success btn-cons m-b-10" type="button"><i class="fa fa-cloud-upload"></i> <span class="bold">Add embed</span></button>
</a>
#else
#foreach($calendars as $calendar)
{{ $calendar->embed }}
#endforeach
#endif
When using Eloquent to get results from a database you get an instance of Illuminate\Database\Eloquent\Collection. To check if that collection is empty you use $collection->isEmpty() or $collection->isNotEmpty() (L5.4).
#if ($calendars->isNotEmpty())
// Have entries.
#else
<h4>No calendar settings</h4></br>
<a href="{{ route('calendarsettings.create')}}"><button class="btn btn-success btn-cons m-b-10" type="button"><i class="fa fa-cloud-upload"></i> <span class="bold">Add embed</span>
</button></a>
#endif
#foreach($calendars as $calendar)
{{$calendar->embed}}
#endforeach

Bootstrap 3.3.1: Btn-group with RESTful Delete and Patch Buttons not connecting smoothly

While using Laravel and twitter bootstrap 3.3.1, I want to design a button group made up of two smoothly connected buttons, which look like that: [ Edit | Delete ]
Because of RESTful API and so on, I wanted to use routes based on at least a DELETE call. Therefore I need to put a POST or PATCH and a DELETE button together. Using blade syntax and form builder, it looks like that:
<div class="btn-group btn-group-xs" role="group">
<div class="btn-group btn-group-xs" role="group">
<a href="{{route('routeTo.edit', $param)}}" type="submit" class="btn btn-warning">
<span class="glyphicon glyphicon-pencil"></span>
</a>
{!! Form::open(array('route' => array('routeTo.delete', $param), 'method' =>
'delete', 'class' => 'btn-group')) !!}
<button type="submit" class="btn btn-mini btn-danger">
<span class="glyphicon glyphicon-trash"></span>
</button>
{!! Form::close() !!}
</div>
</div>
But what appears is not a smoothly connected button-group, but a separated one, which also have a break line.
Also this Thread ( Why Twitter Bootstrap 2 btn-group doesn't work? ) tries to solve the problem in a earlier version, but their solution also doesn't work out for me.
Any thoughts and ideas how to combine POSTS and forms in a button-group? Thanks!
btn-group requires the child btn elements to be siblings, so all you'll need to do is:
{!! Form::open(array('route' => array('class' => 'btn-group', 'routeTo.delete',$param), 'method' =>'delete')) !!}
<div class="btn-group btn-group-xs" role="group">
<a href="{{route('routeTo.edit', $param)}}" class="btn btn-warning">
<span class="glyphicon glyphicon-pencil"></span>
</a>
<button type="submit" class="btn btn-mini btn-danger">
<span class="glyphicon glyphicon-trash"></span>
</button>
</div>
{!! Form::close() !!}
Also, the type attribute on an anchor is completely different to type on an input/button.
Hope this helps!

Escaping trouble - Blade Template in Laravel 5.1

My view contains the following code
#foreach ($building as $maps)
<div class="btn-group">
<a class="btn btn-primary" role="button" href="{{ URL::asset('floorPlans/$maps') }}" aria-expanded="false" aria-controls="collapseExample">
{{ $x }}
</a>
</div>
<?php $x++; ?>
#endforeach
Yet this is resulting in the follwoing HTML
<div class="btn-group">
<a class="btn btn-primary" role="button" href="http://facilities-lara.hslc.wisc.edu/floorPlans/$maps" aria-expanded="false" aria-controls="collapseExample">2</a>
</div>
With $maps still being appended to URL instead of the value within $maps. Is it possible to retrieve the value within a blade template?
Thanks,
Otterman
Everything between the blade tags is just normal PHP. So you can simple concatenate the string and the variable:
{{ URL::asset('floorPlans/'.$maps) }}

Categories