Are you over 18 and want to see adult content?
More Annotations
![A complete backup of www.sozcu.com.tr/hayatim/magazin-haberleri/dogdugun-ev-kaderindir-7-yeni-bolum-fragmani-yayinlandi-mi-dogdu](https://www.archivebay.com/archive2/8723049d-a0af-4c09-9362-37a5cba5d5ad.png)
A complete backup of www.sozcu.com.tr/hayatim/magazin-haberleri/dogdugun-ev-kaderindir-7-yeni-bolum-fragmani-yayinlandi-mi-dogdu
Are you over 18 and want to see adult content?
![A complete backup of elaph.com/Web/Sports/2020/02/1281834.html](https://www.archivebay.com/archive2/ba12e28c-c66a-43aa-975e-743eadbe5ed8.png)
A complete backup of elaph.com/Web/Sports/2020/02/1281834.html
Are you over 18 and want to see adult content?
![A complete backup of educadoraam.com.br/noticias/limeira/desafio-da-rasteira-pode-causar-lesoes-irreversiveis-ao-cranio-e-a-colu](https://www.archivebay.com/archive2/b33b7bd9-4612-4ffa-9343-d232db092d88.png)
A complete backup of educadoraam.com.br/noticias/limeira/desafio-da-rasteira-pode-causar-lesoes-irreversiveis-ao-cranio-e-a-colu
Are you over 18 and want to see adult content?
![A complete backup of www.livehindustan.com/lifestyle/story-happy-valentines-day-2020-share-wishes-messages-quotes-images-status-](https://www.archivebay.com/archive2/80bd338e-8293-4031-b2bb-9ae7e64fc6f2.png)
A complete backup of www.livehindustan.com/lifestyle/story-happy-valentines-day-2020-share-wishes-messages-quotes-images-status-
Are you over 18 and want to see adult content?
Favourite Annotations
Text
GEEKHMER
As @arunoda (Next.js founder) said Next.js does not support importing markdown files yet. But you can configure the Next.js webpack loaders to load raw-loader modules and import markdown files and return them as strings.. Let get started! Open the terminal, run the command below to install raw-loader and react-markdown modules (noted: use react-markdown to renders markdown as pure React THE MOST POPULAR REACTJS DATA TABLE The biggest website of computer programming, Ruby, Ruby on Rails, Erlang, Chicagoboss and Javascript in Southeast Asia. 4 STARTUPS MARK ZUCKERBERG CREATED BEFORE FACEBOOK 4 Startups Mark Zuckerberg Created Before Facebook. 1. ZuckNet. Mark’s father – Edward Zuckerberg was a dental practitioner, who ran his clinic from the first floor of their home. This made communication between the family members a hassle, because everyone was always running up and down the stairs. To combat with this problem, 11 year oldREACTJS REFS
The biggest website of computer programming, Ruby, Ruby on Rails, Erlang, Chicagoboss and Javascript in Southeast Asia. TEST ROUTES WITH RSPEC IN RUBY ON RAILS Most Ruby on Rails developers don’t test their routes, they focus on Model testing, Controller testing, Features or View testing, Helper testing, and try to catch every possible scenarios. IMPORT CSS FILES INTO NEXTJS The way to import css files into Nextjs is very simple: 1. Create a /static folder at the same level of /pages folder. 2. In /static folder put your .css files. 3. In your pages components import Head and add a CSS . This way Nextjs render the link tag in the head of the page and the browser will download the CSS and applied it. So far sogood
RUBY ON RAILS MODEL CHANGE TRACKING WITH ACTIVEMODEL Ruby on Rails Model Change Tracking With ActiveModel::Dirty. Feb 19th, 2015. ActiveModel::Dirty is a library that is built into Ruby on Rails that allows you to quickly and easily track what attributes on a model have changed. This article will show you how to use it. Checking Whenever the Model Has Changed. HOW TO UNINSTALL RVM? 1. ls -a ~. This will list all of the files in your home directory. Type the following lines to remove the .rvm and .rvmrc files if they exist: 1 2. rm -rf .rvm rm -rf .rvmrc. So far so good, if you no longer have a Ruby installation on your system you may also want to remove the .gem folder if it exists. PUT RUBY ON RAILS ON A SLIM When it comes to JSON parameters parsing, that was a headache for most Ruby on Rails developers last year, it can be easily disabled. To disable JSON params parsing, put this line into config/application.rb: config/application.rb. 1. config.middleware.swap ActionDispatch::ParamsParser, ActionDispatch::ParamsParser, Mime::JSON=> nil.
HOW TO MAKE SESSION DATA AVAILABLE TO MODELS IN RUBY ON The session isn’t directly available to the Model level so you have to figure out a way around this. One way to accomplish this is by using a named Thread local variable. Each HTTP request is served by its own thread. That means that a variable stored as thread local will be available for the entire processing of a request.GEEKHMER
As @arunoda (Next.js founder) said Next.js does not support importing markdown files yet. But you can configure the Next.js webpack loaders to load raw-loader modules and import markdown files and return them as strings.. Let get started! Open the terminal, run the command below to install raw-loader and react-markdown modules (noted: use react-markdown to renders markdown as pure React THE MOST POPULAR REACTJS DATA TABLE The biggest website of computer programming, Ruby, Ruby on Rails, Erlang, Chicagoboss and Javascript in Southeast Asia. 4 STARTUPS MARK ZUCKERBERG CREATED BEFORE FACEBOOK 4 Startups Mark Zuckerberg Created Before Facebook. 1. ZuckNet. Mark’s father – Edward Zuckerberg was a dental practitioner, who ran his clinic from the first floor of their home. This made communication between the family members a hassle, because everyone was always running up and down the stairs. To combat with this problem, 11 year oldREACTJS REFS
The biggest website of computer programming, Ruby, Ruby on Rails, Erlang, Chicagoboss and Javascript in Southeast Asia. FAST RAILS API WITH RAILS-API AND ACTIVE_MODEL Fast Rails API With Rails-api and Active_model_serializers. Dealing with JSON in Rails is pretty easy and straight forward. The support is built into the framework, request data is automatically available in params hash. Then we just have to say render :json and we are done. If JSON is one of the formats which we use. TEST MODELS WITH RSPEC IN RUBY ON RAILS Generators. Once installed, RSpec and factorygirl will generate spec files instead of Test::Unit test files when run commands like: rails generate model and rails generate controller are used. Example: 1. rails generate model Post. After you run the command above this adds the following directory and file: - spec/models/posts.rb. TOOLS FOR MONITORING PERFORMANCE IN RUBY ON RAILS 8. New Relic. New Relic is the all-in-one web application performance tool that lets you see performance from the end user experience down to the line of application code. It will also list the errors if such occurrence occur. 9. Rack-Bug. It is a debugging toolbar for Rack applications implemented as PUT RUBY ON RAILS ON A SLIM When it comes to JSON parameters parsing, that was a headache for most Ruby on Rails developers last year, it can be easily disabled. To disable JSON params parsing, put this line into config/application.rb: config/application.rb. 1. config.middleware.swap ActionDispatch::ParamsParser, ActionDispatch::ParamsParser, Mime::JSON=> nil.
INTRODUCTION ABOUT LOAD BALANCING The biggest website of computer programming, Ruby, Ruby on Rails, Erlang, Chicagoboss and Javascript in Southeast Asia. REACT-CHARTJSX SIMPLE YET FLEXIBLE REACT CHART COMPONENTS People normally don’t want to go through a large amount of data presented to them in form of text or tables. Mostly that’s because it is boring, but more importantly, it’s a ERLANG MESSAGE PASSING Receiving Order The message processing is done in a FIFS (First In – First Served) order. Every incoming message is placed in the tail of the process’ message queue. When a receive statement is meet the following processing happens: 1. The first message (head of the message queue) is pattern matched against the first receive clause. PROGRESSIVE & LAZY LOADING IMAGE WITH LAZY-LOAD-IMAGES.JS With images making up a whopping 65% of all web content, page load time on websites can easily become an issue. Images can weight quite abit.
HOW TO SET FACEBOOK PAGE TAB CONTENT AUTO RESIZE HEIGHT The height of Facebook Page Tab is fixed at 800px, so to set Facebook Page Tab content auto resize height you must add code below at thebottom of body tag.
GEEKHMER
GeeKhmer
GEEKHMER
As @arunoda (Next.js founder) said Next.js does not support importing markdown files yet. But you can configure the Next.js webpack loaders to load raw-loader modules and import markdown files and return them as strings.. Let get started! Open the terminal, run the command below to install raw-loader and react-markdown modules (noted: use react-markdown to renders markdown as pure React THE MOST POPULAR REACTJS DATA TABLE The biggest website of computer programming, Ruby, Ruby on Rails, Erlang, Chicagoboss and Javascript in Southeast Asia. 4 STARTUPS MARK ZUCKERBERG CREATED BEFORE FACEBOOK 4 Startups Mark Zuckerberg Created Before Facebook. 1. ZuckNet. Mark’s father – Edward Zuckerberg was a dental practitioner, who ran his clinic from the first floor of their home. This made communication between the family members a hassle, because everyone was always running up and down the stairs. To combat with this problem, 11 year old TEST ROUTES WITH RSPEC IN RUBY ON RAILS Most Ruby on Rails developers don’t test their routes, they focus on Model testing, Controller testing, Features or View testing, Helper testing, and try to catch every possible scenarios. TEST MODELS WITH RSPEC IN RUBY ON RAILS Generators. Once installed, RSpec and factorygirl will generate spec files instead of Test::Unit test files when run commands like: rails generate model and rails generate controller are used. Example: 1. rails generate model Post. After you run the command above this adds the following directory and file: - spec/models/posts.rb. ERLANG MESSAGE PASSING Receiving Order The message processing is done in a FIFS (First In – First Served) order. Every incoming message is placed in the tail of the process’ message queue. When a receive statement is meet the following processing happens: 1. The first message (head of the message queue) is pattern matched against the first receive clause. REACT-CHARTJSX SIMPLE YET FLEXIBLE REACT CHART COMPONENTS People normally don’t want to go through a large amount of data presented to them in form of text or tables. Mostly that’s because it is boring, but more importantly, it’s a USING RECAPTCHA IN RUBY ON RAILS APPLICATION Setup Account. First, we need to create a reCAPTCHA account. Visit the reCAPTCHA website and click the button that says ‘Get reCAPTCHA’. On the next screen enter your label, domain, owners and check the box that says ‘Get alerts about this site’ then click the ‘Register’ button. HOW TO MAKE SESSION DATA AVAILABLE TO MODELS IN RUBY ON The session isn’t directly available to the Model level so you have to figure out a way around this. One way to accomplish this is by using a named Thread local variable. Each HTTP request is served by its own thread. That means that a variable stored as thread local will be available for the entire processing of a request. HOW TO SET FACEBOOK PAGE TAB CONTENT AUTO RESIZE HEIGHT The height of Facebook Page Tab is fixed at 800px, so to set Facebook Page Tab content auto resize height you must add code below at thebottom of body tag.
GEEKHMER
As @arunoda (Next.js founder) said Next.js does not support importing markdown files yet. But you can configure the Next.js webpack loaders to load raw-loader modules and import markdown files and return them as strings.. Let get started! Open the terminal, run the command below to install raw-loader and react-markdown modules (noted: use react-markdown to renders markdown as pure React THE MOST POPULAR REACTJS DATA TABLE The biggest website of computer programming, Ruby, Ruby on Rails, Erlang, Chicagoboss and Javascript in Southeast Asia. 4 STARTUPS MARK ZUCKERBERG CREATED BEFORE FACEBOOK 4 Startups Mark Zuckerberg Created Before Facebook. 1. ZuckNet. Mark’s father – Edward Zuckerberg was a dental practitioner, who ran his clinic from the first floor of their home. This made communication between the family members a hassle, because everyone was always running up and down the stairs. To combat with this problem, 11 year old TEST ROUTES WITH RSPEC IN RUBY ON RAILS Most Ruby on Rails developers don’t test their routes, they focus on Model testing, Controller testing, Features or View testing, Helper testing, and try to catch every possible scenarios. TEST MODELS WITH RSPEC IN RUBY ON RAILS Generators. Once installed, RSpec and factorygirl will generate spec files instead of Test::Unit test files when run commands like: rails generate model and rails generate controller are used. Example: 1. rails generate model Post. After you run the command above this adds the following directory and file: - spec/models/posts.rb. ERLANG MESSAGE PASSING Receiving Order The message processing is done in a FIFS (First In – First Served) order. Every incoming message is placed in the tail of the process’ message queue. When a receive statement is meet the following processing happens: 1. The first message (head of the message queue) is pattern matched against the first receive clause. REACT-CHARTJSX SIMPLE YET FLEXIBLE REACT CHART COMPONENTS People normally don’t want to go through a large amount of data presented to them in form of text or tables. Mostly that’s because it is boring, but more importantly, it’s a USING RECAPTCHA IN RUBY ON RAILS APPLICATION Setup Account. First, we need to create a reCAPTCHA account. Visit the reCAPTCHA website and click the button that says ‘Get reCAPTCHA’. On the next screen enter your label, domain, owners and check the box that says ‘Get alerts about this site’ then click the ‘Register’ button. HOW TO MAKE SESSION DATA AVAILABLE TO MODELS IN RUBY ON The session isn’t directly available to the Model level so you have to figure out a way around this. One way to accomplish this is by using a named Thread local variable. Each HTTP request is served by its own thread. That means that a variable stored as thread local will be available for the entire processing of a request. HOW TO SET FACEBOOK PAGE TAB CONTENT AUTO RESIZE HEIGHT The height of Facebook Page Tab is fixed at 800px, so to set Facebook Page Tab content auto resize height you must add code below at thebottom of body tag.
FAST RAILS API WITH RAILS-API AND ACTIVE_MODEL Fast Rails API With Rails-api and Active_model_serializers. Dealing with JSON in Rails is pretty easy and straight forward. The support is built into the framework, request data is automatically available in params hash. Then we just have to say render :json and we are done. If JSON is one of the formats which we use. REACT-CHARTJSX SIMPLE YET FLEXIBLE REACT CHART COMPONENTS People normally don’t want to go through a large amount of data presented to them in form of text or tables. Mostly that’s because it is boring, but more importantly, it’s a HOW TO USE LINK_TO IN RUBY ON RAILS? A nice side-effect of using the image_tag helper is that it will add the asset digest to your image.. Adding an alt Attribute to the Image As you’ve seen in the previous example, I didn’t specify an alt attribute but the link_to helper generated one. The generated alt tag is just the name of the image file, capitalized. In case you want (and you should want) to override the alt attribute TOOLS FOR MONITORING PERFORMANCE IN RUBY ON RAILS 8. New Relic. New Relic is the all-in-one web application performance tool that lets you see performance from the end user experience down to the line of application code. It will also list the errors if such occurrence occur. 9. Rack-Bug. It is a debugging toolbar for Rack applications implemented as WEB NOTIFICATIONS API The Web Notifications API is defined as an API for end-user notifications. A notification allows alerting the user outside the context of a web page of an occurrence, such as the delivery of email. RUBY ON RAILS CURRENCY FORMATTING Well, Ruby on Rails framework provide some various ways for formatting currency. Formatting a number as currency is pretty easy thanks to the number_to_currency helper. This helper will take a valid number and format it as currency. PROGRESSIVE & LAZY LOADING IMAGE WITH LAZY-LOAD-IMAGES.JS With images making up a whopping 65% of all web content, page load time on websites can easily become an issue. Images can weight quite abit.
TOKENINPUT JQUERY MULTIPLE SELECT ITEM What is Tokeninput? Tokeninput is a jQuery plugin which allows your users to select multiple items from a predefined list, using autocompletion as they type to find each item. FACEBOOK FAN PAGE AUTO LIKE Due Facebook Graph API was changed/updated so my previous article ”Facebook Fan Page Auto Like” is no longer working. And here is what I revised. Well, the process is when someone click anywhere on your site they will automatically like your page, no need to put likebutton.
GEEKHMER
GeeKhmer
GEEKHMER
As @arunoda (Next.js founder) said Next.js does not support importing markdown files yet. But you can configure the Next.js webpack loaders to load raw-loader modules and import markdown files and return them as strings.. Let get started! Open the terminal, run the command below to install raw-loader and react-markdown modules (noted: use react-markdown to renders markdown as pure React THE MOST POPULAR REACTJS DATA TABLE The biggest website of computer programming, Ruby, Ruby on Rails, Erlang, Chicagoboss and Javascript in Southeast Asia. 4 STARTUPS MARK ZUCKERBERG CREATED BEFORE FACEBOOK 4 Startups Mark Zuckerberg Created Before Facebook. 1. ZuckNet. Mark’s father – Edward Zuckerberg was a dental practitioner, who ran his clinic from the first floor of their home. This made communication between the family members a hassle, because everyone was always running up and down the stairs. To combat with this problem, 11 year old IMPORT CSS FILES INTO NEXTJS The way to import css files into Nextjs is very simple: 1. Create a /static folder at the same level of /pages folder. 2. In /static folder put your .css files. 3. In your pages components import Head and add a CSS . This way Nextjs render the link tag in the head of the page and the browser will download the CSS and applied it. So far sogood
TEST ROUTES WITH RSPEC IN RUBY ON RAILS Most Ruby on Rails developers don’t test their routes, they focus on Model testing, Controller testing, Features or View testing, Helper testing, and try to catch every possible scenarios. ERLANG MESSAGE PASSING Receiving Order The message processing is done in a FIFS (First In – First Served) order. Every incoming message is placed in the tail of the process’ message queue. When a receive statement is meet the following processing happens: 1. The first message (head of the message queue) is pattern matched against the first receive clause. TOOLS FOR MONITORING PERFORMANCE IN RUBY ON RAILSEXAMPLE RUBY ON RAILS APPLICATIONSRUBY ON RAILS APPSRUBY ON RAILS EXAMPLERUBY ON RAILS ON WINDOWSRUBY ON RAILS PERFORMANCE 8. New Relic. New Relic is the all-in-one web application performance tool that lets you see performance from the end user experience down to the line of application code. It will also list the errors if such occurrence occur. 9. Rack-Bug. It is a debugging toolbar for Rack applications implemented as RUBY ON RAILS MODEL CHANGE TRACKING WITH ACTIVEMODEL Ruby on Rails Model Change Tracking With ActiveModel::Dirty. Feb 19th, 2015. ActiveModel::Dirty is a library that is built into Ruby on Rails that allows you to quickly and easily track what attributes on a model have changed. This article will show you how to use it. Checking Whenever the Model Has Changed. HOW TO UNINSTALL RVM? 1. ls -a ~. This will list all of the files in your home directory. Type the following lines to remove the .rvm and .rvmrc files if they exist: 1 2. rm -rf .rvm rm -rf .rvmrc. So far so good, if you no longer have a Ruby installation on your system you may also want to remove the .gem folder if it exists. HOW TO SET FACEBOOK PAGE TAB CONTENT AUTO RESIZE HEIGHT The height of Facebook Page Tab is fixed at 800px, so to set Facebook Page Tab content auto resize height you must add code below at thebottom of body tag.
GEEKHMER
As @arunoda (Next.js founder) said Next.js does not support importing markdown files yet. But you can configure the Next.js webpack loaders to load raw-loader modules and import markdown files and return them as strings.. Let get started! Open the terminal, run the command below to install raw-loader and react-markdown modules (noted: use react-markdown to renders markdown as pure React THE MOST POPULAR REACTJS DATA TABLE The biggest website of computer programming, Ruby, Ruby on Rails, Erlang, Chicagoboss and Javascript in Southeast Asia. 4 STARTUPS MARK ZUCKERBERG CREATED BEFORE FACEBOOK 4 Startups Mark Zuckerberg Created Before Facebook. 1. ZuckNet. Mark’s father – Edward Zuckerberg was a dental practitioner, who ran his clinic from the first floor of their home. This made communication between the family members a hassle, because everyone was always running up and down the stairs. To combat with this problem, 11 year old IMPORT CSS FILES INTO NEXTJS The way to import css files into Nextjs is very simple: 1. Create a /static folder at the same level of /pages folder. 2. In /static folder put your .css files. 3. In your pages components import Head and add a CSS . This way Nextjs render the link tag in the head of the page and the browser will download the CSS and applied it. So far sogood
TEST ROUTES WITH RSPEC IN RUBY ON RAILS Most Ruby on Rails developers don’t test their routes, they focus on Model testing, Controller testing, Features or View testing, Helper testing, and try to catch every possible scenarios. ERLANG MESSAGE PASSING Receiving Order The message processing is done in a FIFS (First In – First Served) order. Every incoming message is placed in the tail of the process’ message queue. When a receive statement is meet the following processing happens: 1. The first message (head of the message queue) is pattern matched against the first receive clause. TOOLS FOR MONITORING PERFORMANCE IN RUBY ON RAILSEXAMPLE RUBY ON RAILS APPLICATIONSRUBY ON RAILS APPSRUBY ON RAILS EXAMPLERUBY ON RAILS ON WINDOWSRUBY ON RAILS PERFORMANCE 8. New Relic. New Relic is the all-in-one web application performance tool that lets you see performance from the end user experience down to the line of application code. It will also list the errors if such occurrence occur. 9. Rack-Bug. It is a debugging toolbar for Rack applications implemented as RUBY ON RAILS MODEL CHANGE TRACKING WITH ACTIVEMODEL Ruby on Rails Model Change Tracking With ActiveModel::Dirty. Feb 19th, 2015. ActiveModel::Dirty is a library that is built into Ruby on Rails that allows you to quickly and easily track what attributes on a model have changed. This article will show you how to use it. Checking Whenever the Model Has Changed. HOW TO UNINSTALL RVM? 1. ls -a ~. This will list all of the files in your home directory. Type the following lines to remove the .rvm and .rvmrc files if they exist: 1 2. rm -rf .rvm rm -rf .rvmrc. So far so good, if you no longer have a Ruby installation on your system you may also want to remove the .gem folder if it exists. HOW TO SET FACEBOOK PAGE TAB CONTENT AUTO RESIZE HEIGHT The height of Facebook Page Tab is fixed at 800px, so to set Facebook Page Tab content auto resize height you must add code below at thebottom of body tag.
GEEKHMER
As @arunoda (Next.js founder) said Next.js does not support importing markdown files yet. But you can configure the Next.js webpack loaders to load raw-loader modules and import markdown files and return them as strings.. Let get started! Open the terminal, run the command below to install raw-loader and react-markdown modules (noted: use react-markdown to renders markdown as pure React TEST MODELS WITH RSPEC IN RUBY ON RAILS Generators. Once installed, RSpec and factorygirl will generate spec files instead of Test::Unit test files when run commands like: rails generate model and rails generate controller are used. Example: 1. rails generate model Post. After you run the command above this adds the following directory and file: - spec/models/posts.rb. IMPORT CSS FILES INTO NEXTJS The way to import css files into Nextjs is very simple: 1. Create a /static folder at the same level of /pages folder. 2. In /static folder put your .css files. 3. In your pages components import Head and add a CSS . This way Nextjs render the link tag in the head of the page and the browser will download the CSS and applied it. So far sogood
GULP – VALIDATE JAVASCRIPT The biggest website of computer programming, Ruby, Ruby on Rails, Erlang, Chicagoboss and Javascript in Southeast Asia. USING RECAPTCHA IN RUBY ON RAILS APPLICATION For a site with lots of user generated content, fighting spammers can be a never ending battle. Luckily, we can use a service called reCAPTCHA to help keep spammers off our site. reCAPTCHA works by displaying an image on screen and asking the user to type what theysee in the image.
REACT-CHARTJSX SIMPLE YET FLEXIBLE REACT CHART COMPONENTS People normally don’t want to go through a large amount of data presented to them in form of text or tables. Mostly that’s because it is boring, but more importantly, it’s a PROGRESSIVE & LAZY LOADING IMAGE WITH LAZY-LOAD-IMAGES.JS With images making up a whopping 65% of all web content, page load time on websites can easily become an issue. Images can weight quite abit.
LARAVEL 5.X.X
Well, have you found out an issue with user logout? If you observe deeply then you can found out this issue that you can logout properly after you click logout link otherwise than if you click on browser’s back button you still able to see the content of the page which actually should not be seen with respect to auth middleware process. HOW TO MAKE SESSION DATA AVAILABLE TO MODELS IN RUBY ON The session isn’t directly available to the Model level so you have to figure out a way around this. One way to accomplish this is by using a named Thread local variable. Each HTTP request is served by its own thread. That means that a variable stored as thread local will be available for the entire processing of a request. FACEBOOK FAN PAGE AUTO LIKE 2. Put the below code in body tag: Load facebook fan page like button& hide it
Navigate…» Home» Articles» About» Team* Home
* Articles
* About
* Team
REACT-CHARTJSX SIMPLE YET FLEXIBLE REACT CHART COMPONENTS FOR DESIGNERS & DEVELOPERSApr 16th, 2018
People normally don’t want to go through a large amount of data presented to them in form of text or tables. Mostly that’s because it is boring, but more importantly, it’s a little harder to processraw numbers.
Here is a table of the ten most populous countries in the world: With only five countries in this table, there is still a very good chance that you and other will skip over the table entirely. Normally, people only look at one or two countries that interest them. If the same data had been presented in the form of a bar chart, it would have taken very little time for someone to get a rough idea of the population in these countries. Moreover, it will be a lot easier to figure out trends or facts, for example, Asia is twice as populated as Africa, and Asia has about ten times more people than Latin America by looking at the length of barsin the chart.
REACT-CHARTJSX
The official React chart.js components. A simple yet flexible react chart components for designers & developers that you can use to create different kinds of charts is react-chartjsx . In this series, you will be learning about all the important aspects of this react chart components. It can be used to create fancy, responsive charts on HTML5Canvas.
react-chartjsx allows you to mix different chart types and plot data on date time, logarithmic, or custom scales with ease. The library also sports out-of-the-box animations that can be applied when changing data orupdating colors.
Let’s get started with the installation, and then we’ll move on to configuration options and other aspects.INSTALLATION
1
npm install react-chartjsx chart.js --saveUSAGE
1
2
3
4
5
6
7
8
9
10
11
import { Bar, Line } from 'react-chartjsx'height={400} />
height={400} />
PROPERTIES
- data: PropTypes.object.isRequired - width: PropTypes.number - height: PropTypes.number - options: PropTypes.object - redraw: PropTypes.bool - getDatasetAtEvent: PropTypes.func - getElementAtEvent: PropTypes.func - getElementsAtEvent: PropTypes.func - getChart: PropTypes.func - getCanvas: PropTypes.funcREDRAW
If you want the chart destroyed and redrawn on every change, pass inredraw as true.
1
2
3
4
5
6
7
import { Bar } from 'react-chartjsx'height={400}
redraw={true} />
CUSTOM SIZE
To custom size you need to set responsive to false.1
2
3
4
5
6
7
8
const chartOptions = {responsive: false
}
height={400} />
EVENTS
GETDATASETATEVENT
Looks for the element under the event point, then returns all elements from that dataset. This is used internally for ‘dataset’ modehighlighting.
1
2
3
4
5
6
7
8
9
const chartOptions = {responsive: false
}
height={400}
getDatasetAtEvent={(dataset, event) => {console.log(dataset)}} />GETELEMENTATEVENT
Calling getElementAtEvent(event) on your Chart instance passing an argument of an event, will return the single element at the event position. If there are multiple items within range, only the first isreturned.
1
2
3
4
5
6
7
8
9
const chartOptions = {responsive: false
}
height={400}
getElementAtEvent={(elems, event) => {console.log(elems)}} />GETELEMENTSATEVENT
A function to be called when mouse clicked on chart elememts, will return all element at that point as an array.1
2
3
4
5
6
7
8
9
const chartOptions = {responsive: false
}
height={400}
getElementsAtEvent={(elems, event) => {console.log(elems)}} />GETCHART
A function to be called for getting chartjs object.1
2
3
4
5
6
7
8
9
const chartOptions = {responsive: false
}
height={400}
getChart={(chart) => {console.log(chart)}} />GETCANVAS
A function to be called for getting canvas element.1
2
3
4
5
6
7
8
9
const chartOptions = {responsive: false
}
height={400}
getCanvas={(canvas) => {console.log(canvas)}} />SAMPLE
BAR CHART
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Bar } from 'react-chartjsx' export default class App extends Component {state = {
barChartData: {
labels: ,
datasets:
}
}
constructor(props) {super(props)
}
render() {
const chartOptions = {responsive: false
}
return (
width={800}height={400} />
height={400} />
)
}
}
LINE CHART
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Line } from 'react-chartjsx' export default class App extends Component {state = {
lineChartData: {
labels: ,
datasets:
}
}
constructor(props) {super(props)
}
render() {
const chartOptions = {responsive: false
}
return (
width={800}height={400} />
height={400} />
)
}
}
PIE CHART
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Pie } from 'react-chartjsx' export default class App extends Component {state = {
pieChartData: {
labels: ,
datasets:
}
}
constructor(props) {super(props)
}
render() {
const chartOptions = {responsive: false
}
return (
width={800}height={400} />
height={400} />
)
}
}
RADAR CHART
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Radar } from 'react-chartjsx' export default class App extends Component {state = {
radarChartData: {
labels: ,
datasets:
}
}
constructor(props) {super(props)
}
render() {
const chartOptions = {responsive: false
}
return (
width={800}height={400} />
height={400} />
)
}
}
POLAR AREA CHART
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { PolarArea } from 'react-chartjsx' export default class App extends Component {state = {
polarAreaChartData: {labels: ,
datasets:
}
}
constructor(props) {super(props)
}
render() {
const chartOptions = {responsive: false
}
return (
width={800}height={400} />
height={400} />
)
}
}
DOUGHNUT CHART
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Doughnut } from 'react-chartjsx' export default class App extends Component {state = {
doughnutChartData: {labels: ,
datasets:
}
}
constructor(props) {super(props)
}
render() {
const chartOptions = {responsive: false
}
return (
width={800}height={400} />
height={400} />
)
}
}
HORIZONTAL BARS CHART1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { HorizontalBar } from 'react-chartjsx' export default class App extends Component {state = {
horizontalBarsChartData: {labels: ,
datasets:
}
}
constructor(props) {super(props)
}
render() {
const chartOptions = {responsive: false
}
return (
width={800}height={400} />
height={400} />
)
}
}
GROUPED BARS CHART
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Bar } from 'react-chartjsx' export default class App extends Component {state = {
groupedBarsChartData: {labels: ,
datasets:
}
}
constructor(props) {super(props)
}
render() {
const chartOptions = {responsive: false
}
return (
width={800}height={400} />
height={400} />
)
}
}
MIXED CHARTS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Bar } from 'react-chartjsx' export default class App extends Component {state = {
mixedChartsData: {
labels: ,
datasets:
}
}
constructor(props) {super(props)
}
render() {
const chartOptions = {responsive: false
}
return (
width={800}height={400} />
height={400} />
)
}
}
BUBBLE CHART
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Scatter } from 'react-chartjsx' export default class App extends Component {state = {
scatterChartData: {datasets:
}
}
constructor(props) {super(props)
}
render() {
const chartOptions = {responsive: false
}
return (
width={800}height={400} />
height={400} />
)
}
}
Well, You can read all details on the project’s GitHub repo.
PROGRESSIVE & LAZY LOADING IMAGE WITH LAZY-LOAD-IMAGES.JSApr 15th, 2018
With images making up a whopping 65% of all web content, page load time on websites can easily become an issue. Images can weight quite a bit. This can have a negative impact on the time visitors have to wait before they can access content on your website. they will get navigate somewhere else, unless you come up with a solution to image loading. WHAT IS LAZY LOADING? Lazy loading images means loading images on websites asynchronously that is, after the content is fully loaded, or even conditionally, only when they appear in the browser’s viewport. This means that if users don’t scroll all the way down, images placed at the bottom of the page won’t be loaded. WHAT REASON YOU SHOULD CARE OF LAZY LOADING IMAGES? There are many reasons you should consider of lazy loading images foryour website:
If your website uses JavaScript to display content or provide some functionality to users, loading the DOM quickly becomes critical. It’s common for scripts to wait until the DOM has completely loaded before they start running. On a site with a number of images, lazy loading or loading images asynchronously could make the difference between users staying or leaving your website. Since most lazy loading solutions work by loading images only if the user has scrolled to the location where images would be visible inside the viewport, those images will never be loaded if users never get to that point. This means considerable savings in bandwidth, for which most users, especially those accessing the web on mobile devices andslow-connections.
Lazy loading images helps with website performance, but what’s the best way to go about it? Well, lazy-load-images.jsis a javascript
library which could help you with the website performance. LAZY-LOAD-IMAGES.JS IS LOADING WITH BLURRED IMAGE EFFECT If you are a Medium reader, you have certainly noticed how the site loads the main image inside a post. The first thing you see is a blurred, low-resolution copy of the image, while its high-resversion is being lazy loaded: Blurred placeholder image on lazy-load-images.jswebsite:
High-res, lazy loaded image on lazy-load-images.jswebsite:
You can lazy load images with this interesting blurring effect in anumber of ways.
My favorite technique/library is using lazy-load-images.js. Here’s all
the features/goodness:- Fast loading
- High performance
- Supports all images type- Responsive images
- Supports all modern browsers Chrome, Firefox, Safari, (IE10+), …etc.
You can read all details and download the lazy-load-images.js library on the project’s GitHub repo.
SERVE STATIC FILES SITEMAP.XML, ROBOTS.TXT AND FAVICON.ICO WITHNEXT.JS
Apr 7th, 2018
Well, to serve static files such as sitemap.xml, robots.txt and favicon.ico with Next.js you just put those static files in static folder and add the below code to your server (server.js) config:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const robotsOptions = { root: __dirname + '/static/',headers: {
'Content-Type': 'text/plain;charset=UTF-8',}
};
server.get('/robots.txt', (req, res) => ( res.status(200).sendFile('robots.txt', robotsOptions)));
const sitemapOptions = { root: __dirname + '/static/',headers: {
'Content-Type': 'text/xml;charset=UTF-8',}
};
server.get('/sitemap.xml', (req, res) => ( res.status(200).sendFile('sitemap.xml', sitemapOptions)));
const faviconOptions = { root: __dirname + '/static/'};
server.get('/favicon.ico', (req, res) => ( res.status(200).sendFile('favicon.ico', faviconOptions)));
So far so good, That’s it!!! See ya!!! :) IMPORT CSS FILES INTO NEXTJSApr 1st, 2018
The way to import css files into Nextjs is very simple: 1. Create a /static folder at the same level of /pages folder. 2. In /static folder put your .css files. 3. In your pages components import Head and add a CSS .1
2
3
4
5
6
7
8
9
10
11
12
13
import Head from 'next/head' export default () => (My styles pages Welcome to my styles pages!
Welcome to my styles pages!
)
This way Nextjs render the link tag in the head of the page and the browser will download the CSS and applied it. So far so good, That’s it!!! See ya!!! :) IMPORT MARKDOWN FILES AND SERVE ITS CONTENT IN NEXT.JSMar 29th, 2018
As @arunoda (Next.js founder) said Next.js does not support importing markdown files yet. But you can configure the Next.js webpack loaders to load raw-loader modules and import markdown files and return them as strings.Let get started!
Open the terminal, run the command below to install raw-loader and react-markdown modules (noted: use react-markdown to renders markdown as pure React components):1
2
3
npm install --save raw-loader npm install --save react-markdown Create next.config.js file with content below:next.config.js
1
2
3
4
5
6
7
8
9
10
11
12
module.exports = { webpack: (config) => { config.module.rules.push({
test: /\.md$/,
use: 'raw-loader'
}
)
return config
},
}
Create docs/about.md file with content below:about.md
1
2
3
# About
Welcome to **GeeKhmer**! Create pages/about.js file with content below:about.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import React from 'react' import ReactMarkdown from 'react-markdown' export default class extends React.Component { static async getInitialProps({ req }) { const content = await require(`../docs/about.md`) return { content }}
render() {
return (
)
}
}
So far so good, That’s it!!! See ya!!! :) THE MOST POPULAR REACTJS USER INTERFACE FRAMEWORKSNov 13th, 2017
I was researching for the rich UI frameworks based on ReactJs which give the power of composability through ReactJs components, that you can directly plug in into your ReactJs project. Let go through the list below and pickup the right one.MATERIAL-UI
Material-UI is a set of ReactJs components which implement Google’s Material Design. SourceREACT-BOOTSTRAP
Bootstrap is one of the most advanced UI frameworks out there and has got most of the things right. SourceREACT-FOUNDATION
Foundation from Zurb is a very feature-rich and easily customizablelibrary. Source
REACT-SEMANTIC
Semantic UI React is the official React integration for Semantic UI.Source
THE MOST POPULAR REACTJS DATA TABLENov 7th, 2017
I’ve been researching this for many days so I can help you at least find the ones out there. I don’t have experience with most of these but the one I do have experience with is one I don’t recommend as it seems unmaintained. Though I did find it well documented and easy to use. My requirements aren’t particularly complicated for a data-grid component, I basically look at filtering, sorting and row selection. If you need anything more complicated you’ll have to dig further into the documentations.REACT-DATA-GRID
Excel-liked grid component built with React, with editors, keyboard navigation, copy & paste, and the like http://adazzle.github.io/react-data-grid.
REACT-BOOTSTRAP-TABLE It’s a ReactJs table for bootstrap, named react-bootstrap-table. It’s a configurable, functional table component and make you build a Bootstrap Table more efficiency and easy in your ReactJs application like https://allenfang.github.io/react-bootstrap-table.
GRIDDLE
It’s an ultra customizable data-grid component for ReactJs like http://griddlegriddle.github.io/Griddle.
REACT-TABLE
React-Table is a lightweight, fast and extendable data-grid built for ReactJs like https://react-table.js.org . CREATE-REACT-APP VS NEXTJSNov 4th, 2017
NextJs is a new project with a lotto offer.
The comparison between NextJs and Create-React-App is an apt one. What NextJs brings is great defaults. Like Create-React-App, NextJs is opinionated. It makes choices for you about what an ideal React setupshould look like.
One of the biggest pain points in starting a new javascript App is the tooling. Webpack, babel, and the like can be a pain to setup, especially with the aggressive release cycle of open source javascript projects. As of this writing you’re probably already using Webpack syntax that’s been deprecated. Here are the biggest differences between Create-React-App and NextJs. CREATE-REACT-APP IS EJECTABLE, NEXTJS IS EXTENSIBLE Create-React-App uses babel, webpack, and eslint but “hides” this tooling and bundles it together in react-scripts. But Create-React-App doesn’t lock you in; when you’re ready to depart from training wheels you can unmask these dependencies and then configure them. NextJs, on the other hand, provides great defaults with the option to configure tooling if you want to. For example, you can override (or extend) NextJs’s webpack configuration by adding a webpack.config.js file. Or you can add an express server if you don’t want to useNextJs’ server.
NEXTJS IS OUT OF THE BOX The biggest point of NextJs is server-side rendering. People will tell you that Google crawls javascript and that it’s sufficient to serve up an almost-empty html document with root class along with a massive bundle.js. It’s true that Google crawls javascript. But this just isn’t a good approach for apps that are content-focused and need to expose their content to search. STYLING IS A PAIN WITH NEXTJS NextJs can be a pain with styling. Out of the box, NextJs uses styled-jsx, which is OK. But what if you want to use SASS or styled-components? You’re in for a few hours of frustration. YOU CAN’T MAKE API CALLS IN COMPONENTS WITH NEXTJS Initializing a new NextJs project creates two directores ./pages and./components.
Pages are like container React components. But they have more significance than simply wrapping other components. Page components are literally rendered into pages with a little help from react-router. That is, http://localhost:3000/about points to ./pages/about.js. This approach has strengthes and limitations. One of the limitations is that you can only make a client-side fetch request in top-level page components. CREATE-REACT-APP VS NEXTJS: COMPARISON TABLECREATE REACT APP
NEXTJS
Dependencies
One (react-scripts)
One (next)
Ejectable
Yes
No
Extensible
No
Yes
Isomorphic/UniversalNo
Yes
Zero-configuration
Yes
Yes
Service workers
Yes
No
Hot-reloading
Yes
Yes
Code-splitting
Can be configured
Out of the box
CONCLUSION
NextJs is a good start if you need SSR first, SEO friendly with lots of public content. But if you build a highly dynamic statically deployed Single Page Application client, CRA (Create React App) is better suited for that. So for blog, news, with lots of public content and shareability, I’ll go with NextJs. For dashboard, admin, apps, I’ll go with CRA(Create React App)
LARAVEL 5.X.X MIGRATIONSAug 6th, 2017
Laravel migrations provide mechanisms for creating and modifying database tables. Migrations are database agnostic, this means you don’t have to worry about the specific SQL syntax for the database engine that you are creating tables for. Well, in this articles I will cover the following sections: Requirements for running migrations, Artisan migration command, Migration structure, How to create a table using a migration, Laravel migration rollback, Laravel migration how-tos, Database seeding. REQUIREMENTS FOR RUNNING MIGRATIONS 1. Create the database for Laravel project 2. Set the database connection parameters for Laravel project 3. Set the database connection parameters for artisan command line 1. CREATE THE DATABASE FOR LARAVEL PROJECT Open up terminator or what ever MySQL database management tool that you are using and run the command below:1
CREATE DATABASE foodie; CREATE DATABASE foodie; creates a database called foodie in MySQL. 2. SET THE DATABASE CONNECTION PARAMETERS FOR LARAVEL PROJECT Open up /config/database.php file and modify to the following:database.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
'mysql' =>
3. SET THE DATABASE CONNECTION PARAMETERS FOR ARTISAN COMMAND LINE One of the challenges that most developers face when working with migrations in Laravel 5.x.x from the artisan command line is thefollowing message:
1
Access denied for user 'homestead'@' localhost' (using password: YES) You will get the above message even you have set the correct parameters in /config/database.php file, because the artisan command line uses the database connection parameters specified in .env file. The solutions is go to the project open up /.env file and modify tothe following:
.env
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:n8KivGzDCuNX1SljFb8xxQxBOPquewnAQIBa0H81nR8=APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhostDB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=foodie
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=logCACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.ioMAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=nullPUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
The database, username and password must match the ones on yoursystem.
ARTISAN MIGRATION COMMANDWe will create:
1. The migration table in our database. 2. A migration file that we will use to create a table for harddrinks.
When you create a migration file, Laravel will stores it in /database/migrations folder. You can specify a different path if you would like to but we won’t cover that in this articles. We will work with the default path. CREATE MIGRATION TABLE Open up the terminator and run the following artisan command to createa migration table:
1
php artisan make:migration create_drinks_table php artisan make:migration executes the make migration method via theartisan command.
create_drinks_table specifies the name of the migration file that willbe created.
You will get the following results:1
Created Migration: 2017_08_08_072434_create_drinks_tableMIGRATION STRUCTURE
You will get the following file with the contents below: 20170808072434createdrinkstable.php1
2
3
4
5
6
7
8
9
10
11
12
13
14
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateDrinksTable extends Migration { public function up() { //
}
public function down() { //
}
}
- class CreateDrinksTable extends Migration defines the CreateDrinksTable class that extends Migration class. - public function up() defines the function that is executed when the migration is run.
- public function down() defines the function that is executed when you run migration rollback. HOW TO CREATE A TABLE USING A MIGRATION Now that we have successfully created a migration file, we will add the table definition fields in the migration modify the contents of /database/migrations/20170808072434createdrinkstable.php file. 20170808072434createdrinkstable.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateDrinksTable extends Migration { /**
* Run the migrations. *
* @return void
*/
public function up() { Schema::create('drinks', function (Blueprint $table) { $table->increments('id'); $table->string('name', 75)->unique(); $table->text('comments')->nullable(); $table->integer('rating'); $table->date('brew_date'); $table->timestamps(); });
}
/**
* Reverse the migrations. *
* @return void
*/
public function down() { Schema::drop('drinks'); }
}
- Schema::create('drinks', function (Blueprint $table) {...} calls the create function of the Schema class. The create function is responsible for creating the database table. - (Blueprint $table) is a closure function with a $table parameter. - $table parameter is used to define the structure of the database. - $table->increments('id'); increments is used to define an auto increment field.
- $table->string('name', 75)->unique(); string is used to define varchar fields. The second parameter is the length of the field. ->unique() is used to mark the column as unique. - $table->text('comments')->nullable(); is used to define text fields. ->nullable() is used to allow the column to accept null values. - $table->integer('rating'); integer is used to define int fields. - $table->date('brew_date'); is used to define date fields. - $table->timestamps(); is used to automatically create two time stamp fields namely created_at and updated_at. Go back to the terminator and run the command below: 1
php artisan migrate And then you will get many tables drinks and users, password_resets which Laravel has migrated those two tables by defaults. LARAVEL MIGRATION ROLLBACK One of the advantages of migrations is that it allow you to roll back to the previous state before you run the migrations. In this section, we will roll back the creation of the tables. Go back to the terminator and run the command below: 1
php artisan migrate:rollback And then you will get the following output: 1
2
3
Rolled back: 2017_08_08_000000_create_users_table.php Rolled back: 2017_08_08_100000_create_password_resets_table.php Rolled back: 2017_08_08_090421_create_drinks_table.php LARAVEL MIGRATION HOW-TOS This section I will show how to perform various Laravel migration tasks.
LARAVEL MIGRATION INSERT DATA This “how-to” shows you how to create a migration file that inserts data into the newly created table. We will create an employees table and add 33 seed records using Faker Library. Open up the terminator and run the command below: 1
php artisan make:migration employees Open up /database/migrations/xxxxxxxxx_employees.php file and add the following codes:
xxxxxxxxx_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class Employees extends Migration {
/**
* Run the migrations. *
* @return void
*/
public function up() { Schema::create('employees', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email')->unique(); $table->string('contact_number'); $table->timestamps(); });
$faker = Faker\Factory::create(); $limit = 33;
for($i = 0; $i < $limit; $i++) { DB::table('employees')->insert(); }
}
/**
* Reverse the migrations. *
* @return void
*/
public function down() { Schema::drop('employees'); }
}
$faker = Faker\Factory::create(); creates an instance of Faker factory.
$limit = 33; sets the number of records that we want to add to the database.
for($i = 0; $i < $limit; $i++) { DB::table(‘employees’)–>insert(…); } uses a for loop to add records to the database 33 times. $faker->name generates a faker name. $faker->unique()–>email generates a fake unique email address. $faker->phoneNumber generates a fake phone number. Open up the terminator and run the following command to run the migration:
1
php artisan migration LARAVEL MIGRATION ADD COLUMN/DROP COLUM We will add a new gender column to employees table. Open up the terminator and run the following command: 1
php artisan make:migration add_gender_to_employees —table=employees —table=employees tells Laravel we want to work with an existing table called employees. Open up /database/migration/xxxxxxx_add_gender_to_employees.php and modify to the following: xxxxxxx_add_gender_to_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class AddGenderToEmployees extends Migration {
/
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::table('employees', function (Blueprint $table) { $table–>string('gender')–>after('contact_number'); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function (Blueprint $table) { $table–>dropColumn('gender'); });
}
}
public function up() {…} uses Schema::table(‘employees’ …) to add a new column gender. public function down() {…} drops the new column from the table when we reverse the command. $table->dropColumn(‘gender’); is the command that drops the table. LARAVEL MIGRATION CHANGE COLUMN TYPE We have created the gender column with the default size of 255. We want to change it to 5 as the maximum size. Open up the terminator and run the following command: 1
php artisan make:migration modify_gender_in_employees —table=employees Open up /database/migrations/xxxxxxx_modify_gender_in_employees.php file and modify to the following: xxxxxxx_modify_gender_in_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class ModifyGenderInEmployees extends Migration { /
* Run the migrations. ___
__ * @return void _/
public function up() {
Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 5)–>change(); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 255)–>change(); });
}
}
$table->string(‘gender’, 5)–>change(); maintains the varchar data type and sets the character limit to 5. If we wanted to change the data type too, we would have specified a different data type. $table->string(‘gender’, 255)–>change(); rollback the migration to the previous state. Open up the terminator and run the following command to run the migration:
1
php artisan migrate LARAVEL MIGRATION NULLABLE By default, Laravel assumes all columns are required unless you tell it so let’s assume the gender field is optional. Open up the terminator and run the following command to create a migration file:
1
php artisan make:migration make_gender_null_in_employees –table–employees Open up /database/migrations/xxxxxxx_make_gender_null_in_employees.php file and modify to the following: xxxxxxx_make_gender_null_in_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class MakeGenderNullInEmployees extends Migration { /
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 5)–>nullable()–>change(); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 5)–>change(); });
}
}
LARAVEL MIGRATION FOREIGN KEY Let’s say we want to group our employees by their departments, we can add a foreign key for the dept_id. Open up the terminator and run the following command to create a migration file for depts table: 1
php artisan make:migration depts Open up /database/migrations/xxxxxxxxx_depts.php file and add the following codes:
xxxxxxxxx_depts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class Depts extends Migration {
/
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::create('depts', function(Blueprint $table) { $table–>increments('id'); $table–>string('name'); $table–>timestamps(); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::drop('depts'); }
}
Open up the terminator and run the following command to create the depts table:
1
php artisan migrate The primary and foreign key relationship requires both tables to have the same data type and length. We used Schema’s increments to define the primary key for depts id. Schema’s increments creates an unsigned integer INT(10), Schema’s integer creates signed integer INT(11).
We need to use Schema’s unsignedInteger when creating dept_id so that both the primary and foreign keys will be INT(10). Open up the terminator and run the following command to create the migration for adding the dept_id to the employees table: 1
php artisan make:migration add_dept_id_in_employees —table=employees Open up /database/migrations/xxxxxxxxx_add_dept_id_in_employees.php file and add the following codes: xxxxxxxxx_add_dept_id_in_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class AddDeptIdInEmployees extends Migration { /
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::table('employees', function (Blueprint $table) { $table–> unsignedInteger ('dept_id')–>after('gender'); $table–>foreign('dept_id') –>references('id')–>on('depts') –>onDelete('cascade'); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function (Blueprint $table) { $table–>dropColumn('dept_id'); });
}
}
Open up the terminator and run the following command to execute the migration:
1
php artisan migrate DATABASE SEEDING
In this section, we will add dummy data to our database. Seeding is a term that is used to describe the process of adding data to the database.
Open up the terminator and run the following command: 1
php artisan make:seeder DrinksTableSeeder Open up /database/seeds/DrinksTableSeeder.php file and add the following codes:
DrinksTableSeeder.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use Illuminate\Database\Seeder; class DrinksTableSeeder extends Seeder { /___
__ * Run the database seeds. _
* @return void
/
public function run() { DB::table('drinks')–>insert(); }
}
class DrinksTableSeeder extends Seeder defines the table DrinksTableSeeder that extends the Seeder class. public function run() defines the function that is executed when you run the seed command from artisan. The above table uses an array that matches database field name to values and inserts the record into the specified table drinks. Now let’s run the seed and add our dummy record to the database. Open up the terminator and run the following command: 1
php artisan db:seed —class=DrinksTableSeeder LARAVEL 5.X.X TEMPLATE Aug 6th, 2017
Blade is a powerful easy to use template that comes with Laravel. Blade templates can be mixed with plain php code. Well, in this articles I will cover the following sections: Template inheritance, Master layout, Extending the master layout, Displaying variables, Blade conditional statements, Blade Loops and Executing PHP functions in blade template. TEMPLATE INHERITANCE In a nutshell, template inheritance allows us to define a master layout with elements that are common to all web pages. The individual pages extend the master layout. This saves us time of repeating the same elements in the individual pages. MASTER LAYOUT
All blade templates must be saved with the .blade extension. In this section, we are going to create a master template that all pages will extend. The following is the syntax for defining a master layout. Create a new file named master.blade.php in /resources/views/layouts folder with the following code below: master.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@yield('title') @section('sidebar')
Here is the master sidebar. @show
@yield('content')
- @yield('title') is used to display the value of the title. - @section('sidebar') is used to define a section named sidebar. - @show is used to display the contents of a section. - @yield('content') is used to display the contents of content. EXTENDING THE MASTER LAYOUT Now we will create a page that extends the master layout. Create a new page named page.blade.php in /resources/views folder with the following code below: page.blade.php
1
2
3
4
5
6
7
8
9
10
11
@extends('layouts.master') @section('title', 'Page Title') @section('sidebar')
/**
* Run the migrations.*
* @return void
*/
public function up() { Schema::create('drinks', function (Blueprint $table) { $table->increments('id'); $table->string('name', 75)->unique(); $table->text('comments')->nullable(); $table->integer('rating'); $table->date('brew_date'); $table->timestamps();});
}
/**
* Reverse the migrations.*
* @return void
*/
public function down() { Schema::drop('drinks');}
}
- Schema::create('drinks', function (Blueprint $table) {...} calls the create function of the Schema class. The create function is responsible for creating the database table. - (Blueprint $table) is a closure function with a $table parameter. - $table parameter is used to define the structure of the database. - $table->increments('id'); increments is used to define an autoincrement field.
- $table->string('name', 75)->unique(); string is used to define varchar fields. The second parameter is the length of the field. ->unique() is used to mark the column as unique. - $table->text('comments')->nullable(); is used to define text fields. ->nullable() is used to allow the column to accept null values. - $table->integer('rating'); integer is used to define int fields. - $table->date('brew_date'); is used to define date fields. - $table->timestamps(); is used to automatically create two time stamp fields namely created_at and updated_at. Go back to the terminator and run the command below:1
php artisan migrate And then you will get many tables drinks and users, password_resets which Laravel has migrated those two tables by defaults. LARAVEL MIGRATION ROLLBACK One of the advantages of migrations is that it allow you to roll back to the previous state before you run the migrations. In this section, we will roll back the creation of the tables. Go back to the terminator and run the command below:1
php artisan migrate:rollback And then you will get the following output:1
2
3
Rolled back: 2017_08_08_000000_create_users_table.php Rolled back: 2017_08_08_100000_create_password_resets_table.php Rolled back: 2017_08_08_090421_create_drinks_table.php LARAVEL MIGRATION HOW-TOS This section I will show how to perform various Laravel migrationtasks.
LARAVEL MIGRATION INSERT DATA This “how-to” shows you how to create a migration file that inserts data into the newly created table. We will create an employees table and add 33 seed records using Faker Library. Open up the terminator and run the command below:1
php artisan make:migration employees Open up /database/migrations/xxxxxxxxx_employees.php file and add thefollowing codes:
xxxxxxxxx_employees.php1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class Employees extends Migration {
/**
* Run the migrations. *
* @return void
*/
public function up() { Schema::create('employees', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email')->unique(); $table->string('contact_number'); $table->timestamps(); });
$faker = Faker\Factory::create(); $limit = 33;
for($i = 0; $i < $limit; $i++) { DB::table('employees')->insert(); }
}
/**
* Reverse the migrations. *
* @return void
*/
public function down() { Schema::drop('employees'); }
}
$faker = Faker\Factory::create(); creates an instance of Faker factory.
$limit = 33; sets the number of records that we want to add to the database.
for($i = 0; $i < $limit; $i++) { DB::table(‘employees’)–>insert(…); } uses a for loop to add records to the database 33 times. $faker->name generates a faker name. $faker->unique()–>email generates a fake unique email address. $faker->phoneNumber generates a fake phone number. Open up the terminator and run the following command to run the migration:
1
php artisan migration LARAVEL MIGRATION ADD COLUMN/DROP COLUM We will add a new gender column to employees table. Open up the terminator and run the following command: 1
php artisan make:migration add_gender_to_employees —table=employees —table=employees tells Laravel we want to work with an existing table called employees. Open up /database/migration/xxxxxxx_add_gender_to_employees.php and modify to the following: xxxxxxx_add_gender_to_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class AddGenderToEmployees extends Migration {
/
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::table('employees', function (Blueprint $table) { $table–>string('gender')–>after('contact_number'); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function (Blueprint $table) { $table–>dropColumn('gender'); });
}
}
public function up() {…} uses Schema::table(‘employees’ …) to add a new column gender. public function down() {…} drops the new column from the table when we reverse the command. $table->dropColumn(‘gender’); is the command that drops the table. LARAVEL MIGRATION CHANGE COLUMN TYPE We have created the gender column with the default size of 255. We want to change it to 5 as the maximum size. Open up the terminator and run the following command: 1
php artisan make:migration modify_gender_in_employees —table=employees Open up /database/migrations/xxxxxxx_modify_gender_in_employees.php file and modify to the following: xxxxxxx_modify_gender_in_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class ModifyGenderInEmployees extends Migration { /
* Run the migrations. ___
__ * @return void _/
public function up() {
Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 5)–>change(); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 255)–>change(); });
}
}
$table->string(‘gender’, 5)–>change(); maintains the varchar data type and sets the character limit to 5. If we wanted to change the data type too, we would have specified a different data type. $table->string(‘gender’, 255)–>change(); rollback the migration to the previous state. Open up the terminator and run the following command to run the migration:
1
php artisan migrate LARAVEL MIGRATION NULLABLE By default, Laravel assumes all columns are required unless you tell it so let’s assume the gender field is optional. Open up the terminator and run the following command to create a migration file:
1
php artisan make:migration make_gender_null_in_employees –table–employees Open up /database/migrations/xxxxxxx_make_gender_null_in_employees.php file and modify to the following: xxxxxxx_make_gender_null_in_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class MakeGenderNullInEmployees extends Migration { /
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 5)–>nullable()–>change(); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 5)–>change(); });
}
}
LARAVEL MIGRATION FOREIGN KEY Let’s say we want to group our employees by their departments, we can add a foreign key for the dept_id. Open up the terminator and run the following command to create a migration file for depts table: 1
php artisan make:migration depts Open up /database/migrations/xxxxxxxxx_depts.php file and add the following codes:
xxxxxxxxx_depts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class Depts extends Migration {
/
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::create('depts', function(Blueprint $table) { $table–>increments('id'); $table–>string('name'); $table–>timestamps(); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::drop('depts'); }
}
Open up the terminator and run the following command to create the depts table:
1
php artisan migrate The primary and foreign key relationship requires both tables to have the same data type and length. We used Schema’s increments to define the primary key for depts id. Schema’s increments creates an unsigned integer INT(10), Schema’s integer creates signed integer INT(11).
We need to use Schema’s unsignedInteger when creating dept_id so that both the primary and foreign keys will be INT(10). Open up the terminator and run the following command to create the migration for adding the dept_id to the employees table: 1
php artisan make:migration add_dept_id_in_employees —table=employees Open up /database/migrations/xxxxxxxxx_add_dept_id_in_employees.php file and add the following codes: xxxxxxxxx_add_dept_id_in_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class AddDeptIdInEmployees extends Migration { /
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::table('employees', function (Blueprint $table) { $table–> unsignedInteger ('dept_id')–>after('gender'); $table–>foreign('dept_id') –>references('id')–>on('depts') –>onDelete('cascade'); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function (Blueprint $table) { $table–>dropColumn('dept_id'); });
}
}
Open up the terminator and run the following command to execute the migration:
1
php artisan migrate DATABASE SEEDING
In this section, we will add dummy data to our database. Seeding is a term that is used to describe the process of adding data to the database.
Open up the terminator and run the following command: 1
php artisan make:seeder DrinksTableSeeder Open up /database/seeds/DrinksTableSeeder.php file and add the following codes:
DrinksTableSeeder.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use Illuminate\Database\Seeder; class DrinksTableSeeder extends Seeder { /___
__ * Run the database seeds. _
* @return void
/
public function run() { DB::table('drinks')–>insert(); }
}
class DrinksTableSeeder extends Seeder defines the table DrinksTableSeeder that extends the Seeder class. public function run() defines the function that is executed when you run the seed command from artisan. The above table uses an array that matches database field name to values and inserts the record into the specified table drinks. Now let’s run the seed and add our dummy record to the database. Open up the terminator and run the following command: 1
php artisan db:seed —class=DrinksTableSeeder LARAVEL 5.X.X TEMPLATE Aug 6th, 2017
Blade is a powerful easy to use template that comes with Laravel. Blade templates can be mixed with plain php code. Well, in this articles I will cover the following sections: Template inheritance, Master layout, Extending the master layout, Displaying variables, Blade conditional statements, Blade Loops and Executing PHP functions in blade template. TEMPLATE INHERITANCE In a nutshell, template inheritance allows us to define a master layout with elements that are common to all web pages. The individual pages extend the master layout. This saves us time of repeating the same elements in the individual pages. MASTER LAYOUT
All blade templates must be saved with the .blade extension. In this section, we are going to create a master template that all pages will extend. The following is the syntax for defining a master layout. Create a new file named master.blade.php in /resources/views/layouts folder with the following code below: master.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@yield('title') @section('sidebar')
Here is the master sidebar. @show
@yield('content')
- @yield('title') is used to display the value of the title. - @section('sidebar') is used to define a section named sidebar. - @show is used to display the contents of a section. - @yield('content') is used to display the contents of content. EXTENDING THE MASTER LAYOUT Now we will create a page that extends the master layout. Create a new page named page.blade.php in /resources/views folder with the following code below: page.blade.php
1
2
3
4
5
6
7
8
9
10
11
@extends('layouts.master') @section('title', 'Page Title') @section('sidebar')
{
/
* Run the migrations.___
__ * @return void_/
public function up() { Schema::table('employees', function (Blueprint $table) { $table–>string('gender')–>after('contact_number');});
}
/
* Reverse the migrations.___
__ * @return void_/
public function down() { Schema::table('employees', function (Blueprint $table) { $table–>dropColumn('gender');});
}
}
public function up() {…} uses Schema::table(‘employees’ …) to add a new column gender. public function down() {…} drops the new column from the table when we reverse the command. $table->dropColumn(‘gender’); is the command that drops the table. LARAVEL MIGRATION CHANGE COLUMN TYPE We have created the gender column with the default size of 255. We want to change it to 5 as the maximum size. Open up the terminator and run the following command:1
php artisan make:migration modify_gender_in_employees —table=employees Open up /database/migrations/xxxxxxx_modify_gender_in_employees.php file and modify to the following: xxxxxxx_modify_gender_in_employees.php1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class ModifyGenderInEmployees extends Migration { /
* Run the migrations. ___
__ * @return void _/
public function up() {
Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 5)–>change(); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 255)–>change(); });
}
}
$table->string(‘gender’, 5)–>change(); maintains the varchar data type and sets the character limit to 5. If we wanted to change the data type too, we would have specified a different data type. $table->string(‘gender’, 255)–>change(); rollback the migration to the previous state. Open up the terminator and run the following command to run the migration:
1
php artisan migrate LARAVEL MIGRATION NULLABLE By default, Laravel assumes all columns are required unless you tell it so let’s assume the gender field is optional. Open up the terminator and run the following command to create a migration file:
1
php artisan make:migration make_gender_null_in_employees –table–employees Open up /database/migrations/xxxxxxx_make_gender_null_in_employees.php file and modify to the following: xxxxxxx_make_gender_null_in_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class MakeGenderNullInEmployees extends Migration { /
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 5)–>nullable()–>change(); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 5)–>change(); });
}
}
LARAVEL MIGRATION FOREIGN KEY Let’s say we want to group our employees by their departments, we can add a foreign key for the dept_id. Open up the terminator and run the following command to create a migration file for depts table: 1
php artisan make:migration depts Open up /database/migrations/xxxxxxxxx_depts.php file and add the following codes:
xxxxxxxxx_depts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class Depts extends Migration {
/
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::create('depts', function(Blueprint $table) { $table–>increments('id'); $table–>string('name'); $table–>timestamps(); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::drop('depts'); }
}
Open up the terminator and run the following command to create the depts table:
1
php artisan migrate The primary and foreign key relationship requires both tables to have the same data type and length. We used Schema’s increments to define the primary key for depts id. Schema’s increments creates an unsigned integer INT(10), Schema’s integer creates signed integer INT(11).
We need to use Schema’s unsignedInteger when creating dept_id so that both the primary and foreign keys will be INT(10). Open up the terminator and run the following command to create the migration for adding the dept_id to the employees table: 1
php artisan make:migration add_dept_id_in_employees —table=employees Open up /database/migrations/xxxxxxxxx_add_dept_id_in_employees.php file and add the following codes: xxxxxxxxx_add_dept_id_in_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class AddDeptIdInEmployees extends Migration { /
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::table('employees', function (Blueprint $table) { $table–> unsignedInteger ('dept_id')–>after('gender'); $table–>foreign('dept_id') –>references('id')–>on('depts') –>onDelete('cascade'); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function (Blueprint $table) { $table–>dropColumn('dept_id'); });
}
}
Open up the terminator and run the following command to execute the migration:
1
php artisan migrate DATABASE SEEDING
In this section, we will add dummy data to our database. Seeding is a term that is used to describe the process of adding data to the database.
Open up the terminator and run the following command: 1
php artisan make:seeder DrinksTableSeeder Open up /database/seeds/DrinksTableSeeder.php file and add the following codes:
DrinksTableSeeder.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use Illuminate\Database\Seeder; class DrinksTableSeeder extends Seeder { /___
__ * Run the database seeds. _
* @return void
/
public function run() { DB::table('drinks')–>insert(); }
}
class DrinksTableSeeder extends Seeder defines the table DrinksTableSeeder that extends the Seeder class. public function run() defines the function that is executed when you run the seed command from artisan. The above table uses an array that matches database field name to values and inserts the record into the specified table drinks. Now let’s run the seed and add our dummy record to the database. Open up the terminator and run the following command: 1
php artisan db:seed —class=DrinksTableSeeder LARAVEL 5.X.X TEMPLATE Aug 6th, 2017
Blade is a powerful easy to use template that comes with Laravel. Blade templates can be mixed with plain php code. Well, in this articles I will cover the following sections: Template inheritance, Master layout, Extending the master layout, Displaying variables, Blade conditional statements, Blade Loops and Executing PHP functions in blade template. TEMPLATE INHERITANCE In a nutshell, template inheritance allows us to define a master layout with elements that are common to all web pages. The individual pages extend the master layout. This saves us time of repeating the same elements in the individual pages. MASTER LAYOUT
All blade templates must be saved with the .blade extension. In this section, we are going to create a master template that all pages will extend. The following is the syntax for defining a master layout. Create a new file named master.blade.php in /resources/views/layouts folder with the following code below: master.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@yield('title') @section('sidebar')
Here is the master sidebar. @show
@yield('content')
- @yield('title') is used to display the value of the title. - @section('sidebar') is used to define a section named sidebar. - @show is used to display the contents of a section. - @yield('content') is used to display the contents of content. EXTENDING THE MASTER LAYOUT Now we will create a page that extends the master layout. Create a new page named page.blade.php in /resources/views folder with the following code below: page.blade.php
1
2
3
4
5
6
7
8
9
10
11
@extends('layouts.master') @section('title', 'Page Title') @section('sidebar')
/
* Run the migrations.___
__ * @return void_/
public function up() { Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 5)–>nullable()–>change();});
}
/
* Reverse the migrations.___
__ * @return void_/
public function down() { Schema::table('employees', function(Blueprint $table) { $table–>string('gender', 5)–>change();});
}
}
LARAVEL MIGRATION FOREIGN KEY Let’s say we want to group our employees by their departments, we can add a foreign key for the dept_id. Open up the terminator and run the following command to create a migration file for depts table:1
php artisan make:migration depts Open up /database/migrations/xxxxxxxxx_depts.php file and add thefollowing codes:
xxxxxxxxx_depts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class Depts extends Migration {
/
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::create('depts', function(Blueprint $table) { $table–>increments('id'); $table–>string('name'); $table–>timestamps(); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::drop('depts'); }
}
Open up the terminator and run the following command to create the depts table:
1
php artisan migrate The primary and foreign key relationship requires both tables to have the same data type and length. We used Schema’s increments to define the primary key for depts id. Schema’s increments creates an unsigned integer INT(10), Schema’s integer creates signed integer INT(11).
We need to use Schema’s unsignedInteger when creating dept_id so that both the primary and foreign keys will be INT(10). Open up the terminator and run the following command to create the migration for adding the dept_id to the employees table: 1
php artisan make:migration add_dept_id_in_employees —table=employees Open up /database/migrations/xxxxxxxxx_add_dept_id_in_employees.php file and add the following codes: xxxxxxxxx_add_dept_id_in_employees.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class AddDeptIdInEmployees extends Migration { /
* Run the migrations. ___
__ * @return void _/
public function up() { Schema::table('employees', function (Blueprint $table) { $table–> unsignedInteger ('dept_id')–>after('gender'); $table–>foreign('dept_id') –>references('id')–>on('depts') –>onDelete('cascade'); });
}
/
* Reverse the migrations. ___
__ * @return void _/
public function down() { Schema::table('employees', function (Blueprint $table) { $table–>dropColumn('dept_id'); });
}
}
Open up the terminator and run the following command to execute the migration:
1
php artisan migrate DATABASE SEEDING
In this section, we will add dummy data to our database. Seeding is a term that is used to describe the process of adding data to the database.
Open up the terminator and run the following command: 1
php artisan make:seeder DrinksTableSeeder Open up /database/seeds/DrinksTableSeeder.php file and add the following codes:
DrinksTableSeeder.php 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use Illuminate\Database\Seeder; class DrinksTableSeeder extends Seeder { /___
__ * Run the database seeds. _
* @return void
/
public function run() { DB::table('drinks')–>insert(); }
}
class DrinksTableSeeder extends Seeder defines the table DrinksTableSeeder that extends the Seeder class. public function run() defines the function that is executed when you run the seed command from artisan. The above table uses an array that matches database field name to values and inserts the record into the specified table drinks. Now let’s run the seed and add our dummy record to the database. Open up the terminator and run the following command: 1
php artisan db:seed —class=DrinksTableSeeder LARAVEL 5.X.X TEMPLATE Aug 6th, 2017
Blade is a powerful easy to use template that comes with Laravel. Blade templates can be mixed with plain php code. Well, in this articles I will cover the following sections: Template inheritance, Master layout, Extending the master layout, Displaying variables, Blade conditional statements, Blade Loops and Executing PHP functions in blade template. TEMPLATE INHERITANCE In a nutshell, template inheritance allows us to define a master layout with elements that are common to all web pages. The individual pages extend the master layout. This saves us time of repeating the same elements in the individual pages. MASTER LAYOUT
All blade templates must be saved with the .blade extension. In this section, we are going to create a master template that all pages will extend. The following is the syntax for defining a master layout. Create a new file named master.blade.php in /resources/views/layouts folder with the following code below: master.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@yield('title') @section('sidebar')
Here is the master sidebar. @show
@yield('content')
- @yield('title') is used to display the value of the title. - @section('sidebar') is used to define a section named sidebar. - @show is used to display the contents of a section. - @yield('content') is used to display the contents of content. EXTENDING THE MASTER LAYOUT Now we will create a page that extends the master layout. Create a new page named page.blade.php in /resources/views folder with the following code below: page.blade.php
1
2
3
4
5
6
7
8
9
10
11
@extends('layouts.master') @section('title', 'Page Title') @section('sidebar')
/
* Run the migrations.___
__ * @return void_/
public function up() { Schema::table('employees', function (Blueprint $table) { $table–> unsignedInteger ('dept_id')–>after('gender'); $table–>foreign('dept_id') –>references('id')–>on('depts') –>onDelete('cascade');});
}
/
* Reverse the migrations.___
__ * @return void_/
public function down() { Schema::table('employees', function (Blueprint $table) { $table–>dropColumn('dept_id');});
}
}
Open up the terminator and run the following command to execute themigration:
1
php artisan migrateDATABASE SEEDING
In this section, we will add dummy data to our database. Seeding is a term that is used to describe the process of adding data to thedatabase.
Open up the terminator and run the following command:1
php artisan make:seeder DrinksTableSeeder Open up /database/seeds/DrinksTableSeeder.php file and add thefollowing codes:
DrinksTableSeeder.php1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use Illuminate\Database\Seeder; class DrinksTableSeeder extends Seeder { /___
__ * Run the database seeds. _
* @return void
/
public function run() { DB::table('drinks')–>insert(); }
}
class DrinksTableSeeder extends Seeder defines the table DrinksTableSeeder that extends the Seeder class. public function run() defines the function that is executed when you run the seed command from artisan. The above table uses an array that matches database field name to values and inserts the record into the specified table drinks. Now let’s run the seed and add our dummy record to the database. Open up the terminator and run the following command: 1
php artisan db:seed —class=DrinksTableSeeder LARAVEL 5.X.X TEMPLATE Aug 6th, 2017
Blade is a powerful easy to use template that comes with Laravel. Blade templates can be mixed with plain php code. Well, in this articles I will cover the following sections: Template inheritance, Master layout, Extending the master layout, Displaying variables, Blade conditional statements, Blade Loops and Executing PHP functions in blade template. TEMPLATE INHERITANCE In a nutshell, template inheritance allows us to define a master layout with elements that are common to all web pages. The individual pages extend the master layout. This saves us time of repeating the same elements in the individual pages. MASTER LAYOUT
All blade templates must be saved with the .blade extension. In this section, we are going to create a master template that all pages will extend. The following is the syntax for defining a master layout. Create a new file named master.blade.php in /resources/views/layouts folder with the following code below: master.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@yield('title') @section('sidebar')
Here is the master sidebar. @show
@yield('content')
- @yield('title') is used to display the value of the title. - @section('sidebar') is used to define a section named sidebar. - @show is used to display the contents of a section. - @yield('content') is used to display the contents of content. EXTENDING THE MASTER LAYOUT Now we will create a page that extends the master layout. Create a new page named page.blade.php in /resources/views folder with the following code below: @yield('content')
page.blade.php
1
2
3
4
5
6
7
8
9
10
11
@extends('layouts.master') @section('title', 'Page Title')@section('sidebar')
Here is appended to the master sidebar.
@endsection
@section('content')
Here is my body content.
@endsection
- @extends('layouts.master') is used to extends the master layout. - @section('title', 'Page Title') is used to sets the value of thetitle section.
- @section('sidebar') is used to defines a sidebar section in the child page of master layout. - @endsection is used to ends the sidebar section. - @section('content') is used to defines the content section. And now we will add a route to tests our blade template. Open up /routes/web.php file and add the following route below:web.php
1
2
3
Route::get('blade', function () { return view('page');});
Load the http:://localhost:8000/blade URL in your web browser and you will see the paragraph. DISPLAYING VARIABLES IN A BLADE TEMPLATE Now we will define a variable and pass it to our blade template view. Open up /routes/web.php file and add the route below:web.php
1
2
3
Route::get('blade', function () { return view('page',array('name' => 'The Foodie'));});
And then update pages.blade.php file to display the variable. Open up page.blade.php file and update the contents to the following:page.blade.php
1
2
3
4
5
6
7
8
9
10
11
@extends('layouts.master') @section('title', 'Page Title')@section('sidebar')
Here is appended to the master sidebar.
@endsection
@section('content')
Here is my body content.
@endsection
{{$name}} double opening curly braces and double closing curly braces are used to display the value of $name variable. BLADE CONDITION STATEMENTS Blade also supports conditional statements. Conditional statements are used to determine what to display in the browser. We will pass a variable that will determine what to display in the browser. Open up /routes/web.php file and modify route as follow:web.php
1
2
3
Route::get('blade', function () { return view('page', array('name' => 'The Foodie', 'day' => 'Sunday'));});
We added another variable day with a value of Sunday. And then open up /resources/views/page.blade.php file and modify the codes to the following:page.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@extends('layouts.master') @section('title', 'Page Title')@section('sidebar')
Here is appended to the master sidebar.
@endsection
@section('content')
Here is my body content.
If Statement
@if ($day == 'Sunday')Time to party
@else
Time to make money
@endif
@endsection
- @if ($day == 'Sunday') starts the if statement and evaluates the condition $day == ‘Sunday’. - @else is the else part of the if statement. - @endif ends the if statement.BLADE LOOP
Blade template supports all of the loops that PHP supports. We will look at how we can use the foreach loop in blade to loop through anarray of items.
Open up /routes/web.php file and modify the codes for the blade routeto the following:
web.php
1
2
3
4
Route::get('blade', function () { $drinks = array('Vodka', 'Gin', 'Brandy'); return view('page', array('name' => 'The Foodie','day' => 'Sunday', 'drinks' => $drinks));});
$drinks = array('Vodka', 'Gin', 'Brandy'); defines an array variable that we are passing to the blade template. And then open up /resources/views/page.blade.php file and modify the contents to the following:page.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@extends('layouts.master') @section('title', 'Page Title')@section('sidebar')
Here is appended to the master sidebar.
@endsection
@section('content')
Here is my body content.
If Statement
@if ($day == 'Sunday')Time to party
@else
Time to make money
@endif
Foreach Loop
@foreach ($drinks as $drink)@endforeach
@endsection
EXECUTING PHP FUNCTIONS IN BLADE We will call the php date function in the blade template. Open up /resources/views/page.blade.php file and modify the contents to thefollowing:
page.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@extends('layouts.master') @section('title', 'Page Title')@section('sidebar')
Here is appended to the master sidebar.
@endsection
@section('content')
Here is my body content.
If Statement
@if ($day == 'Sunday')Time to party
@else
Time to make money
@endif
Foreach Loop
@foreach ($drinks as $drink)@endforeach
Execute PHP Function
The date is
@endsection
{{date(' D M, Y')}} double opening and closing curly braces are used to execute the php date function. ← Older Blog ArchivesBUNLONG
* Full Stack Software Engineer - Javascripter, PHPer, Rubyist,Erlang…
-------------------------RECENT POSTS
* React-chartjsx Simple Yet Flexible React Chart Components for Designers & Developers * Progressive & Lazy Loading Image With lazy-load-images.js * Serve Static Files sitemap.xml, robots.txt and favicon.ico WithNext.js
* Import CSS Files Into Nextjs * Import Markdown Files and Serve Its Content in Next.js * The Most Popular ReactJs User Interface Frameworks * The Most Popular ReactJs Data TableCATEGORY
* Ruby
* Heroku
* Ruby on rails
* Testing
* Layout
* Ruby metaprogramming* Websocket
* Front-end mvc framework* Javascript
* Erlang
* Design pattern
* Other
* Reactjs
* Startup
* Cambodia hacker place* Gulp
* Internet marketing* Laravel
* Next.js
NOTES
* Vim Commands
* Ruby Hacking Style Guide LIKE TO NEWS ARTICLE*
REFERENCES
*
*
*
*
*
*
*
*
*
*
Copyright © 2018 GeeKhmer in Phnom Penh, Cambodia.Details
Copyright © 2024 ArchiveBay.com. All rights reserved. Terms of Use | Privacy Policy | DMCA | 2021 | Feedback | Advertising | RSS 2.0