06 Laravel - Eloquent (DB) Continued, Validation, Cookies and Sessions
06 Laravel - Eloquent (DB) Continued, Validation, Cookies and Sessions
06 Laravel - Eloquent (DB) Continued, Validation, Cookies and Sessions
• Eloquent: recap
• Selecting all records
• Adding a record
• Eloquent use cases
• Selecting a specific record
• Updating a specific record
• Deleting a specific record
• Validation
• Cookies
• Sessions
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 2
Eloquent: recap
Eloquent: recap
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 5
Eloquent: recap
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 6
Eloquent: additional use cases
Eloquent use cases
• Using the find() method, select a record based on its primary key
• Using the save() method, you can also update existing records:
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 8
Validation
Validation
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 10
Validation
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 11
Validation
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 12
Validation
• In Blade file:
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 13
Cookies
HTTP = stateless protocol
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 15
HTTP = stateless protocol
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 16
Cookie
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 17
Cookies in Laravel
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 18
Cookies in Laravel
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 19
Cookies: inspecting request – response using Postman
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 20
Cookies: what about security?
Visualisation in browser:
• Information is stored locally
• Transmitted with each request
• What about confidential data?
• Some solutions:
• Encryption of cookie value
(=default behavior in Laravel)
• HTTPS
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 21
Cookies: overcoming statelessness
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 22
Cookies versus local storage
Cookies:
• Key-value pairs (strings)
• Used to obtain state in stateless HTTP world
• Transmitted with each Request – Response
Local storage:
• Key-value pairs (strings)
• Used for local data only
• If you want data in local storage available on server, you need to send it explicitly
( cookies)
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 23
Sessions
Overcoming HTTP statelessness
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 25
Sessions
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 26
Sessions
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 27
Sessions in Laravel
• You obtain a reference to the session via $request -> session() method
• Each item has a key (here “my-item”) and value (here contents of $item)
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 28
Retrieving something from the session
• You obtain a reference to the session via $request -> session() method
• Retrieve item based on its key
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 29
Sessions in Laravel
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 30
More information?
• https://laravel.com/docs/master/session
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 31
Questions?
25/03/2020 Web, Mobile and Security – Laravel: Eloquent (DB) continued, Validation, Cookies and Sessions 32