This question already has answers here:
Laravel - Pass more than one variable to view
(12 answers)
Closed 2 years ago.
i need to create one variable of text in LARAVEL
if((strlen($tpesquisa ))<4) {
return view('pesquisa');
///////// for example msgm= 'it is necessary to use more than 4 words to start searching';
}
/////////////// for example msgm= 'were found x results';
return view('pesquisa',compact('produtos'));
and in view print the msgm
<p>{{$msgm}}</p>
how create the variable with value text?
and how can I measure the results?
You can just define
$msgm = 'whatever the text'
And then, in the return view you can do:
return view('pesquisa',compact('produtos', 'msgm'));
Related
This question already has answers here:
PHP If Statement with Multiple Conditions
(11 answers)
Closed 2 years ago.
I had a if statement that return 'active active-c' if the getName is true, but the problem is i wanna put two value on it so I do this:
#if (Route::current()->getName() === 'sonyForm' || 'warnerForm') active active-c #endif
But that ain't work well, how to do that properly?
The other option is to ask the route to check if it matches a set of patterns for the name:
#if (Route::current()->named('sonyForm', 'warnerForm'))
#if (in_array(Route::current()->getName(), ['sonyForm', 'warnerForm']))
active active-c
#endif
This question already has answers here:
how to put a backquote in a backquoted string?
(3 answers)
Closed 2 years ago.
I am trying to initialize a JSON object as a byte in go lang. Here, I am attaching two exmples
var countryRegionData = []byte(`{"name": "srinivas"}`)
var countryRegionData = []byte(`{"name": "srini`vas"}`)
In the first initilization there is no issue, all working as expected.
In the second initialization if you see there is ` between i and v. I have some requirement like this. How to achieve?
A backtick cannot appear in a raw string literal. You can write something like this:
var countryRegionData = []byte("{\"name\": \"srini`vas\"}")
You cannot use escaping in a raw string literal. Either you have to use double-quoted string:
"{\"name\": \"srini'vas\"}"
Or do something like:
`{"name": "srini`+"`"+"vas"}`
This question already has answers here:
Laravel change input value
(7 answers)
Closed 3 years ago.
So I'm manipulating Request and setting an object to new value.
$assignable = ['seats'];
$request->seats = $this->myMethod($request->seats);
var_dump($request->seats); //works
$data = $request->only($assignable);
var_dump($data['seats']); // returns the initial value of 'seats' (without passing through $this->myMethod)
Now I know I could first convert the request object to array and then manipulate the '$data', but the above code is a sample and the real code is much more complicated, it would require to change the whole architecture to do that way.
Has anyone experienced anything like this?
Instead of this:
$request->seats = $this->myMethod($request->seats);
Try this:
$request->merge(['seats' => $this->myMethod($request->seats)]);
This question already has answers here:
How to dynamically create a local variable?
(4 answers)
Closed 8 years ago.
Instance_variable_get value can be assigned to a variable as follows. The following code throws correct output
a = instance_variable_get("#" + "#{code}" + "_resource").get_price(a, b) // working
But unable to assign instance_variable_get value to a variable with dynamic param. Assume the code is a dynamic param which is in loop.
"#{code}_buy" = instance_variable_get("#" + "#{code}" + "_resource").get_price(a, b) //Not working
The above method throws the following error
syntax error, unexpected '=', expecting keyword_end
You could use a hash instead:
hash = {}
hash["#{code}_buy"] = some_value
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Extract Url From a String
I have a string like:
abchghhdgfdgfdfdfhttp://www.rajasthanpatrika.com/News/World/1132013/international news/414309\r\n\t\t\t\t ghjghjfhjvfhjhfj"
I want to extract the URL:
http://www.rajasthanpatrika.com/News/World/1132013/international news/414309
How can I do this?
s = "abchghhdgfdgfdfdfhttp://www.rajasthanpatrika.com/News/World/1132013/international news/414309\r\n\t\t\t\t ghjghjfhjvfhjhfj"
s[/http:\/\/.*?(?=[\r\n\t])/]
# => "http://www.rajasthanpatrika.com/News/World/1132013/international news/414309"