I´m trying to translate a validation message that uses expression like GreaterThan() validation constrain class.
How can I translate this message "This value should be greater than {comparator_value}." ?
Other simple messages without expression it´s working fine
thanks
If you want to to get the min value of GreaterThan. You must replace {comparator_value} with {{ compared_value }}, it will look like below:
This value should be greater than {{ compared_value }}
Hope this can help you!
Related
I would like to pass string input with commas through laravel form text field. You can provide multiple numbers separated by commas, the application will handle imploding into array.
The issue is that laravel (or web browser) by default will change comma to '%2C'. I know it's a safety feature, but this is not too big concern in case of this application.
Is there a way to disable this?
Already tried to use {!! !!} instead of standard {{ }}
{{ Form::text('number', null) }}
Try using POST method in form tag instead of GET method.
It will not show field value in URL.
Is that possible to make route that accept string parameter only for specific string? Example :
Route::get('{user_tipe}/event', 'admin\EventC#index');
That the route, I want to make the user_tipe param is only allow to two string like admin and author. Is that possible?
You can do that using regular expression constraits on your route:
Route::get('{user_tipe}/event', 'admin\EventC#index')->where('user_tipe', 'admin|author');
admin|author is a simple regular expression that will match either the string admin or author
UPDATE
Here you can find how to use the route param constraints when using Route::group
I know Laravel5 Resource method will work like this.
TestControler#index /aa
TestControler#edit /aa/{aa}/edit
..
It's good to work if integer have been inserted.
/aa/1/edit -> work
But it will broken if string is coming.
/aa/aa/edit -> SQLSTATE[22P02]: Invalid text representation ..
So I wanna ask you the question is how should I allow request url thats integer only?
where should I write, route.php or Controller?
and how to abort 404 if string is coming.
any idea?
Expanding on my comment:
When working with Laravel's router, for any parameter you add to a URI definition (such as {id}), you can add a regex constraint. The constraint will take the variable value and test to see if the regex matches the value. If the regex fails, then the route will not be selected.
You do this using the where() method on the route and passing an associative array where the keys correspond to the variables in the URI, and the values are regexes to match. You can add constraints to as many variables in a route's URI as you like.
For example, if you wanted to constrain the id value in your URI to just numbers, you could do something like this:
Route::get("users/{id}", "Users#getUser")->where(["id" => "[0-9]+"]);
The documentation for this feature states:
You may constrain the format of your route parameters using the where method on a route instance. The where method accepts the name of the parameter and a regular expression defining how the parameter should be constrained
See more examples in the documentation available here: https://laravel.com/docs/5.2/routing#parameters-regular-expression-constraints
Thanks to reply, Finally It works great.
But I wanna add this to my post.
Where method will work when I write 'standard' routing like this.
Route::get('/aa/{aa}/edit','TestsController#delete')->name('aa.edit')->where('aa','[0-9]+'); // works great!
But that's not work if I write 'RESTful' routing like this.
Route::resource('/aa', 'TestsController')->where('aa','[0-9]+'); // not work!
So I wrote this to app/route.php, It works very fine.
Route::pattern('aa', '\d+');
Route::get('/aa/{aa}/delete','TestsController#delete')->name('aa.delete')->where('aa','[0-9]+');
Route::resource('/aa', 'TestsController')->where('aa','[0-9]+');
Hello I'm currently working with Laravel 4 forms. I'm struggling to generate a text input with a specific class without choosing a 'default value'. I want to do the following:
{{ Form::text('first_name', array('class' => 'first_name')) }}
However I get this error (htmlentities() expects parameter 1 to be string, array given.) unless I add a default value:
{{ Form::text('first_name', 'Some Value', array('class' => 'first_name')) }}
The default value then populates the field and needs to be deleted before entering a new value. So it can't even be used like a place holder.
Thank you in advance,
Dan
Instead of a value, supply null. (do no supply empty string "")
This will come in handy in the future if you are going to work with Form Model Binding (http://laravel.com/docs/html#form-model-binding) because null will give the value of the given model attribute.
You can pass an empty value "" like,
{{ Form::text('first_name', '', array('class' => 'first_name')) }}
Because Laravel 4's HTML Form Builder API will accept first parameter as name, second parameter as value which is null by default and the third parameter as options array which is an empty array by default.
So basically you can build text input by passing only name like,
{{ Form::text('first_name') }}
And if you are planning to pass options which is the third argument, you must pass second argument also.
See API Doc here http://laravel.com/api/source-class-Illuminate.Html.FormBuilder.html#235-246
I found it better to use the Input::old('first_name') for your default value instead of just "", like:
{{ Form::text('first_name', Input::old('first_name')) }}
This way, if you go back to the form with invalid data and pass the form input, it will reload the old input that the user previously inputted. In this case, first_name is/can be bound to the first_name field in your database table as well.
Edit: Yes, the third option is an array of input options, such as text field id, size, etc. or any other HTML attribute.
Keenan :)
I want to create advance query builder using PHP code.
Input :
search_String_1 AND( search_String_2 OR search_String_3) ... so on
Goal :
check AND / OR operator rules including () parenthesis and convert it into following String:
Query :
db.table.search_field LIKE '
search_String_1' AND ( db.table.search_field LIKE 'search_String_2' OR db.table.search_field LIKE 'search_String_3')'
My efforts:
I have use preg_match() but I dont know how to check all operator and query sequences by best solution. Also I have exploded user input by "blank_space" , so i have all token in one array. I am still trying to find solution. If I am wrong or there is a good solution please suggest me to do so.
Thanks for your help.
Take a look at this class. It may be usefull.
http://www.phpclasses.org/browse/file/12314.html