Laravel, how to put multiple value on #if [duplicate] - laravel

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

Related

Create variable laravel [duplicate]

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'));

Request only method returns original request array [duplicate]

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)]);

Ruby error with non-required arguments on method [duplicate]

This question already has answers here:
How to mix required argument and optional arguments in ruby?
(2 answers)
Closed 6 years ago.
This is on Ruby 2.1.8.
I have the following method:
def self.notify(methods=[], user, message_key, notifiable_id=nil, notifiable_type=nil)
# Do some stuff
end
When I try to use this method and pass in valid values, I get the following error:
SyntaxError:
: syntax error, unexpected '=', expecting ')'
...er, message_key, notifiable_id=nil, notifiable_type=nil)
... ^
: Can't assign to nil
...message_key, notifiable_id=nil, notifiable_type=nil)
...
For the life of me I cannot figure out why. If I remove the =nil from notifiable_id and notifiable_type in the method arguments, everything works fine.
And FWIW assigning methods to an empty array is not the issue. If I don't assign that or assign it to nil I get the same issue.
Any thoughts appreciated.
You have a default defined for the 'methods' argument but then no defaults for user or message_key. You cannot have any arguments without a default value after an argument with a default value.

Extract URL from a string? [duplicate]

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"

XCode: change auto-completion for "if (...) {" to "if (...) [new line]{ " [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Xcode 4 with opening brace on new line
Is there a way to change the auto adding bracket to start from a new line? So:
if (a != 0) {
}
when { is added, it will be like:
if (a != 0)
{
}
is this possible?
It's kind of tricky after Xcode 4.2. You can check this answer if you want to do it by yourself.
There is also an app called Snippet Edit that can do it for you. But it's not free...

Resources