So I am now working with the update part of my program, now i want to populate my forms with the older records from my database to edit it. Now my problem is the radio button, how can select the true one. I tried this code, i use if on my radio buttons
{{ Form::label('Type','Type')}}
{{ Form::radio('ctype', '1',if(($item->bname)==1){true}) }}
{{ Form::label('Rooster','Rooster')}}
{{ Form::radio('ctype', '0') }}
{{ Form::label('Hen','Hen')}}
But I just get error 500, please help
In the documentation it says:
echo Form::radio('name', 'value', true);
So you should go this way:
{{ Form::radio('ctype', '1', $item->bname == 1) }}
You shouldn't need any additional brackets. Third param is a simple boolean value.
Related
I just started to use Laravel Collective. However, I encounter a problem when I try to extract the value from the Select Form.
{!! Form::open(['method'=>'POST','action'=>['ExpenseController#store'],'files' =>false], array('enctype'=>'multipart/form-data','id'=>'customer_contact','class' => 'form-validate1')) !!}
{{ Form::select('account_categories', $account_name,null, array("class"=>"dropdown-toggle form-control",'placeholder'=>'Please select ...')) }}
{!! Form::close() !!}
And it will look like this
But when I try to get the value from this select form via $request and return back to the Laravel, it output number instead of string value selected by user like this:
"account_categories":"5"
How can I get the string value selected by users from this SELECTBOX FORM ?
How do I escape out of blade syntax to show html in an if data exists statement?
{{ $manager->first_name or 'add' }}
Will just show the html tags as well. All I saw in the docs was escap
That kind of logic is not the best way to do things... In your view, You should do the following
#if (null !== $manager->first_name)
{{ $manager->first_name }}
#else
add
#endif
There may be some changes needed to the code for the if/else statement to validate correctly, but this is the basic idea.
you can do this {!! $manager->first_name or 'add' !!}
Just an addition to celia's answer; you should still escape the data:
{!! isset($manager->first_name) ? e($manager->first_name) : 'add' !!}
I have an "artist" resource, and on the show route page I have a form. I am using Laravel Blade syntax. As part of this form, I am trying to send the page ID to the back end of a Laravel 4 project. I am doing it this way:
{{Form::hidden('artist-id',null, array(
'id' => '{{$artist->id}}',
));}}
However, when using this, the browser throws an error, because it is not rendering the $artist->id variable within the brackets before the outside brackets of the input form.
Is there a way around this or another way to pass back this variable for the resource? Thank you!
So anything inside the blade tags {{ }} is treated as standard PHP. Using further {{ }} inside existing blade tags is just going to throw a big error.
Because anything inside the blade tags is treated as PHP you can simply do the following
{{ Form::hidden('artist-id', null, ['id' => $artist->id]) }}
Although posting that input isn't going to give you the value you want, because the value supplied is null. The id attribute is the html ID given to the html attribute. You need the following to set the value on the input, which will then be posted in with your form data
{{ Form::hidden('artist-id', $artist->id) }}
You don't need to nest your blade call like that, this should work:
{{ Form::hidden('artist-id', null, array('id' => $artist->id)) }}
I have 2 email fields and I am using
{{ Form::text('email[]', Input::old('email'),array('class' => 'large-2', 'placeholder' => 'email address','id'=>'email')) }}`
if I use [] to get multiple values for same variable, it is giving error in view page if posted back some data. for example if some fields are mandatory and if user fail to fill those, page will be redirected to same view page from where it was launched.
In such cases it is showing error.
How to fix this issue?
One text field can contain only one data. So, you need another text field to achieve that. if you don't want to show the multiple emails, you can use hidden fields.
{{ Form::hidden('email[]', Input::old('email1'))
{{ Form::hidden('email[]', Input::old('email2'))
Or you can use select. Laravel allow array data if use select field.
For example:
{{ Form::select('size', array('L' => 'Large', 'S' => 'Small')) }}
http://laravel.com/docs/html#drop-down-lists
I am trying to create a simple back button on a page. The user can arrive to this page from two different pages so I would like to know from which page he arrived. Is that possible?
In Laravel, you can do something like this: Back (assuming you're using Blade).
Laravel 4
{{ URL::previous() }}
Laravel 5+
{{ url()->previous() }}
Laravel documentation
I know this is an oldish question but I found it whilst looking for the same solution. The solution above doesn't appear to work in Laravel 4, you can however use this now:
Go Back
Hope this helps people who look for this feature in L4
(Source: https://github.com/laravel/framework/pull/501/commits)
Laravel 5.2+, back button
Back
Indeed using {{ URL:previous() }} do work, but if you're using a same named route to display multiple views, it will take you back to the first endpoint of this route.
In my case, I have a named route, which based on a parameter selected by the user, can render 3 different views. Of course, I have a default case for the first enter in this route, when the user doesn't selected any option yet.
When I use URL:previous(), Laravel take me back to the default view, even if the user has selected some other option. Only using javascript inside the button I accomplished to be returned to the correct view:
Voltar
I'm tested this on Laravel 5.3, just for clarification.
The following is a complete Blade (the templating engine Laravel uses) solution:
{!! link_to(URL::previous(), 'Cancel', ['class' => 'btn btn-default']) !!}
The options array with the class is optional, in this case it specifies the styling for a Bootstrap 3 button.
On 5.1 I could only get this to work.
Back
You can use javascript for this provblem.
It's retrieve link from browser history.
<script>
function goBack() {
window.history.back();
}
</script>
<button onclick="goBack()">Go Back</button>
One of the below solve your problem
URL::previous()
URL::back()
other
URL::current()
You can use {{ URL::previous() }}
But it not perfect UX.
For example, when you press F5 button and click again to Back Button with {{ URL::previous() }} you will stay in.
A good way is using {{ route('page.edit', $item->id) }} it always true page you wanna to redirect.
<i class="fa fa-angle-left"></i> Continue Shopping
This worked in Laravel 5.8