here is laravel blade selectyears which generates select from 2013 to 2015 and need set first option to null.
{!! Form::selectYear('year', 2013, 2015) !!}
Just have another array array(''=>"Select Year") in your select
I guess that you need null because you might need to place some text like Select Year like that.
Here is What you need
{!! Form::select('year', range(2013, 2015) + array(''=>"Select Year")) !!}
Related
I have 3 select tags with a lot of options inside them. One for year, one for month and one for day.
The question is ... How to set selected on the option I want.
I was thinking of this solutions:
Pass the options as array to the view. After that forech them in the select tag and with "#if" check every single one if its the right one and set "selected:selected".
But in my case this isnt good solution because I have many options ... that means the array will be very very big.
Put if statement in every option in the html and check if its te right one and set "selected:selected" to that option. This is also a bad solution ... there will be like 200+ if statements.
Maybe create 3 db tables with this options inside. Getting them in the controller method, foreaching them in the select tag and checking them with if statement and setting "selected" to the right one.
I really dont know if Im thinking in the right way. I will apriciate some help.
what you r doing is right here is a solution that it did worked for me, i have a user city, and when i want the user to update the city i show it as selected
just pass the arrays to the view then :
#foreach ($citys as $city)
#if (Auth::user()->city_id == $city->id)
<option value="{{$city->id}}" selected="selected">{{$city->name}}</option>
#else
<option value="{{$city->id}}">{{$city->name}}</option>
#endif
#endforeach
here is a short version u can use
#foreach ($citys as $city)
<option value="{{$city->id}}" #if (Auth::user()->city_id == $city->id) selected="selected" #endif > {{$city->name}}</option>
#endforeach
I want to display the total payments overall, and total payments for this month using only one variable.
Controller
$payments = Payment::where('user_id', auth()->user()->id)->get();
return view('subscribers.payments', compact(['payments']));
View
<label>Total payments</label>
<p>{{ $payments->sum('amount') }}</p>
<label>For this month</label>
<p>{{ $payments->whereMonth('created_at', now()->month)->sum('amount') }}</p>
Actually the total payments overall displayed. But the "for this month" it is not working and returns me an error below:
Method Illuminate\Database\Eloquent\Collection::whereMonth does not exist.
Someone could tell me where I went wrong? and proper way to achieve this?
Isn't querying by month alone going to create a problem later when you have more than one year of data? I would just use the start of the current month.
<p>{{ $payments->where('created_at', '>=', now()->startOfMonth())->sum('amount') }}</p>
so whereMonth is unfortunately only available with the query builder. You could filter the items after they've been retrieved:
$payments->filter(function ($payment) {
return $payment->created_at->month == now()->month;
})->sum('amount')
HI I have following Kendo Dropdown, even though I have a value in ng-model, the dropdown is not selecting the default values.
<select name="myDropDown"
id="myDropDown"
class="width-90"
kendo-drop-down-list k-data-text-field="'key'"
k-data-value-field="'value'"
k-data-source="myDataSource"
ng-model="model.selectedProperty"></select>
model.selectedProperty does have the value . However the UI does't select the options.
DataSource Values:
[{"key":"Critical","value":0},{"key":"High","value":1},{"key":"Medium","value":2},{"key":"Low","value":3}]
model.selectedProperty = 1
The above one should have selected the second option, but the dropdown selects none
Well I have to make the selected value same object as in the list:
$scope.model.selectedProperty = {"key":"Critical","value":0}
And I updated the select tag to,
<select name="myDropDown"
id="myDropDown"
class="width-90"
ng-model="model.selectedProperty"
ng-options="option.key for option in myDataSource track by option.value">
</select>
I want to write an if statement to show timestamp in diffForHumans format for timestamps less than less than 5 days old and in toFormattedDatesString for anything older than that.
For example today is 31/10/17, so timestamp for 28/10/2017 should show - 3 days ago and timestamp for 20/10/2017 should show Oct 20, 2017.
What logic should I use to achieve this?
In your Model e.g A.php, create an accessor like this,
public function getCreatedAtAttribute(){
if($this->created_at->diffInDays(Carbon::now()) > 5){
return $this->created_at->toFormattedDateString();
}else{
return $this->created_at->diffForHumans();
}
}
and in your view you can access it as
{!! $a->created_at !!}
Using Carbon you can do that like this.
1
Code
Carbon::createFromFormat('d/m/Y', '28/10/2017')->diffForHumans();
Result
3 days
2
Code
Carbon::createFromFormat('d/m/Y', '28/10/2017')->toFormattedDateString();
Result
Oct 28, 2017
I have an Apex Tabular form:
ID Name Title Class ROW_EDIT <br>
1 Smith Mgr AP (checkbox)<br>
etc...
I am trying to activate the 'checkbox' ROW_EDIT column - which has a default value of Y - when the user changes the value for the tabular form column Class (Select list) in the same row. I can change the ROW_EDIT attribute to text (ie, Y) if easier...
I have no apex_items for the page to reference - all columns are tabular form.
I have researched some dynamic change events - but I can't seem to get the row-reference to set correctly.
Any help would be greatly appreciated.
Thanks
Unfortunately, last time I saw APEX 4.2 was 2 years ago and I don't have it now.
The idea is in the following:
Add onchange event to select list. I don't remember is there an easy way to do this. If not, you can create a select list manually using APEX_ITEM package. To do this, write in the source query:
select apex_item.select_list_from_lov (
p_idx => 10,
p_value => class, -- it is a name of a table column
p_lov => 'my_lov_name',
p_attributes => 'onchange="my_func.call(this);"')
from ...
In page properites (JavaScript section), create a javascript function:
function my_func () {
this.parentElement.parentElement.getElementsByTagName("input")[0].checked = true;
}
Parameter this in the function is a reference to select list. Hence, this.parentElement.parentElement - reference to row with the triggering select list, getElementsByTagName("input")[0] is a checkbox. If you have several input elements in the row, use proper index instead of 0.
How this JavaScript code works you can check here: https://codepen.io/anon/pen/NvPmPp