Answer the question
In order to leave comments, you need to log in
How to use your variables and functions in the view in laravel?
On the page, you need to display words with adequate endings depending on the number. Such words are enough.
How to do it right? I just started learning laravel, it's not very clear where to put the logic.
public static $time_hour = array('час', 'часа', 'часов');
public static $time_minute = array('минута', 'минуты', 'минут');
/*
* остальные слова...
*/
public static function getNumEnding($number, $ends)
{
if($number == 0) {
return $ends[0];
}
if ($number < 1) {
if ($number < 0.3) {
return '¼ '.$ends[1];
}
if ($number > 0.6) {
return '¾ '.$ends[1];
}
return '½ '.$ends[1];
}
$i = ceil($number) % 1000;
if ($i >= 11 && $i <= 19) {
return $number.' '.$ends[2];
}
switch ($i) {
case (1):
return $number.' '.$ends[0];
case (2):
case (3):
case (4):
return $number.' '.$ends[1];
default:
return $number.' '.$ends[2];
}
}
echo getNumEnding(5, $time_hour); //5 часов
echo getNumEnding(3, $time_minute);//3 минуты
Answer the question
In order to leave comments, you need to log in
If Laravel 5.1 then:
laravel.com/docs/5.1/blade#service-injection
How do I do.
1. We create a class with our functionality. For example in a folderapp
// app/Some.php
namespace App;
class Some {
public function getValue() {
return "VALUE";
}
}
app/Providers/AppServiceProvider.php
. register
:public function register()
{
$this->app->bind('Some', function($app)
{
return new \App\Some;
});
}
}
@inject('some', 'Some')
<div>
Value: {{ $some->getValue() }}.
</div>
I have a similar configuration at work, Windows7 64bit operating system, JavaEE development on Intellij IDEA, a WebLogic server running locally, and it's also excruciatingly painful. Increased the memory to 6GB - did not help. I asked to upgrade the processor - they are greedy. In general, you have to pay for the speed of development and cross-platform with the speed of the work itself. Therefore, my hobby works as fast as possible :-)
Do you have a processor, memory or disk rests? Analyze and understand for yourself what you need: more memory, ssd or change the entire configuration.
I have been developing JEE applications for 10 years, and the configuration has always been weaker. At the moment, I’ve been developing on a laptop for 3 years at work, I don’t remember exactly which processor (I’m writing now from home), before the i3 / 5/7 line it was produced, it seems Core 2. 3 GB of memory. I run the Idea environment, a couple of JBoss server instances, an httpd web server, and I load it all in SOAPUi - tens of thousands of requests through web services, and everything works quite well for itself. While the load test is in progress, I work in Idea without any problems.
Home i3 3000 GHz, 4 GB memory. MySQL is installed, there are about 300 thousand records in the database now (an unpacked dump weighs half a gigabyte). There is no application server. I launch my software from Idea, which works quite intensively with the base, I myself continue to program and launch other developments - there are no hints of brakes at all.
Follow the path of exceptions: stop all running components one by one (server, development environment, etc.) until you notice that the computer “breathed deeply”, then you will understand where the problem is. In the end, the task manager clearly shows who is eating memory or processor. There is also a good chance that JEE has nothing to do with it at all, and the problem is in faulty hardware or a crippled OS.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question