1 2 3 4 5 6 7 8 |
FROM node:10 WORKDIR /usr/src/app COPY package*.json ./ RUN npm install pm2 -g RUN npm install COPY . . EXPOSE 8080 CMD ["pm2-runtime", "server.js"] |
Full Stack LAMP, MEAN, DevOps Consultant
1 2 3 4 5 6 7 8 |
FROM node:10 WORKDIR /usr/src/app COPY package*.json ./ RUN npm install pm2 -g RUN npm install COPY . . EXPOSE 8080 CMD ["pm2-runtime", "server.js"] |
Javascript allows us to declare fields inside the class. We can access its own fields or properties by creating an instance of a class. Example:
1 2 3 4 5 |
Class Devreto { postId = 1; } const devreto = new Devreto(); devreto.postId ; //1 |
The null coalescing assignment operator is a shorthand for null coalescing operations. Let’s take a example code
1 |
$data['date'] = $data['date'] ?? new DateTime(); |
Arrow functions also called “short closures”. We can always access the parent scope, there’s no need for the use keyword. Here is a simple example with an arrow function.
1 2 3 |
$items = [1,2,3,4,5]; $factor = 10; array_map(fn ($item) => $item * $factor, $items) |
Laravel has in-built increment() and decrement() functions to increase or decrease a value of the column, by 1 or with the given number. Below are the examples:
1 |
User::find($user_id)->increment('post_count'); |
Let us see an example of how to calculate the difference between dates using Javascript. First, write an HTML code with Javascript as below:
1 2 3 4 5 |
const d1 = new Date("12/12/2018"); const d2 = new Date("12/12/2020"); const timeDiff = d2.getTime() - d1.getTime(); const DaysDiff = timeDiff / (1000 * 3600 * 24); console.log("Days of difference between:"+ d1 +"<br> and "+d2+" is:" +DaysDiff); |
This is useful for migrations when you can’t rollback. It can easily be run in artisan mode or you can create a console command.
1 2 3 4 |
foreach(\DB::select('SHOW TABLES') as $table) { $table_array = get_object_vars($table); \Schema::drop($table_array[key($table_array)]); } |
PHP 7.4 allows for underscores to be used to visually separate numeric values. It looks like this:
1 2 |
$unformattedNumber = 123456789.78; $formattedNumber = 123_456_789.78; |