Laravel Web Application Development PDF

Summary

This document is a lecture on Laravel web application development and explains the Model-View-Controller (MVC) design pattern. It covers the roles of the Model, View, and Controller components and how they interact to build dynamic web applications. The lecture was part of the ICT Electives program in 2024.

Full Transcript

WORKING WITH LARAVEL Building Web Applications with Laravel ICT Electives 3 2024. Prepared by JC Akwunwa 2...

WORKING WITH LARAVEL Building Web Applications with Laravel ICT Electives 3 2024. Prepared by JC Akwunwa 2 MVC PATTERN The Model-View-Controller (MVC) design pattern is a widely used architectural pattern in software development, particularly in web and GUI-based applications. It aims to separate the concerns of an application into three interconnected components: Model, View, and Controller. This separation helps in organizing code, improving maintainability, and facilitating collaboration among developers. Features of MVC include : It provides a clear separation of business logic, Ul logic, and input logic. It offers full control over your HTML and URLs which makes it easy to design web application pattern. It is a powerful URL-mapping component using which we can build applications that have comprehensible and searchable URLs. It supports Test Driven Development (TDD). ICT Electives 2024. Prepared by JC Akwunwa 3 COMPONENTS OF MVC PATTERN 1. Model: The Model component corresponds to all the data-related logic that the user works with. The Model represents the application's data and business logic. It encapsulates the data-related operations, such as data retrieval, manipulation, validation, and storage, i.e either the data that is being transferred between the View and Controller components or any other business logic-related data. It can add or retrieve data from the database. It responds to the controller’s request because the controller can’t interact with the database by itself. The model interacts with the database and gives the required data back to the controller It is independent of the user interface and communicates with the database or external services to fetch or update data. In an ideal scenario, the Model should be reusable and not tightly coupled to any specific presentation or interaction logic. ICT Electives 2024. Prepared by JC Akwunwa 4 COMPONENTS OF MVC PATTERN 2. View: The View component is used for all the UI logic of the application. It generates a user interface for the user. Views are created by the data which is collected by the model component but these data aren’t taken directly but through the controller. It only interacts with the controller. The View is responsible for presenting data to the user and handling user interface interactions. It receives data from the Model and renders it in a format suitable for presentation, such as HTML for web applications or GUI components for desktop applications. The View should not contain any business logic; its primary concern is the visual representation of data and user interaction. ICT Electives 2024. Prepared by JC Akwunwa 5 COMPONENTS OF MVC PATTERN 3. Controller: The controller is the component that enables the interconnection between the views and the model so it acts as an intermediary. The controller doesn’t have to worry about handling data logic, it just tells the model what to do. It processes all the business logic and incoming requests, manipulates data using the Model component, and interact with the View to render the final output. The Controller acts as an intermediary between the Model and the View. It processes user input, performs appropriate actions, and updates the Model and View accordingly. It receives user requests, decides which Model methods to invoke, and determines which View to render in response. Controllers handle the application's flow, orchestrate interactions between components, and manage the overall application behavior. ICT Electives 2024. Prepared by JC Akwunwa 6 LOGIC OF MVC PATTERN ICT Electives 2024. Prepared by JC Akwunwa 7 LOGIC OF MVC PATTERN Let’s imagine an end-user sends a request to a server to get a list of students studying in a class. 1. The server would then send that request to that particular controller that handles students. 2. That controller would then request the model that handles students to return a list of all students studying in a class. 3. The model would query the database for the list of all students and then return that list back to the controller. If the response back from the model was successful, then the controller would ask the view associated with students to return a presentation of the list of students. 4. This view would take the list of students from the controller and render the list into HTML that can be used by the browser. 5. The controller would then take that presentation and returns it back to the user. Thus ending the request. 6. If earlier the model returned an error, the controller would handle that error by asking the view that handles errors to render a presentation for that particular error. That error presentation would then be returned to the user instead of the student list presentation ICT Electives 2024. Prepared by JC Akwunwa 8 KEY PRINCIPLES AND THE MVC PATTERN Separation of Concerns: MVC separates different aspects of an application (data, presentation, and control logic), making it easier to manage and modify each component independently. Modularity and Reusability: By isolating different concerns, MVC promotes code reuse and modularity, which enhances maintainability and scalability. Testability: Since each component has a specific responsibility, it's easier to write unit tests for individual components, leading to better test coverage and overall code quality. Parallel Development: MVC enables parallel development by allowing teams to work on different components simultaneously without interfering with each other's work. ICT Electives 2024. Prepared by JC Akwunwa 9 PRINCIPLES ARCHIVED BY MVC PATTERN The MVC architectural pattern allows us to adhere to the following design principles: 1. Divide and conquer. The three components can be somewhat independently designed. 2. Increase cohesion. The components have stronger layer cohesion than if the view and controller were together in a single UI layer. 3. Reduce coupling. The communication channels between the three components are minimal and easy to find. 4. Increase reuse. The view and controller normally make extensive use of reusable components for various kinds of UI controls. The UI, however, will become application-specific, therefore it will not be easily reusable. 5. Design for flexibility. It is usually quite easy to change the UI by changing the view, the controller, or both. and working of the MVC framework ICT Electives 2024. Prepared by JC Akwunwa 10 ADVANTAGES OF MVC Codes are easy to maintain, and they can be extended easily. The MVC model component can be tested separately. The components of MVC can be developed simultaneously. It reduces complexity by dividing an application into three units. Model, view, and controller. It supports Test Driven Development (TDD). It works well for Web apps that are supported by large teams of web designers and developers. This pattern helps to test components independently as all classes and objects are independent of each other Search Engine Optimization (SEO) Friendly.e MVC framework ICT Electives 2024. Prepared by JC Akwunwa 11 DISADVANTAGES OF MVC It is difficult to read, change, test, and reuse this model It is not suitable for building small applications. The inefficiency of data access in view. The framework navigation can be complex as it introduces new layers of abstraction which requires users to adapt to the decomposition criteria of MVC. Increased complexity and Inefficiency of data. ICT Electives 2024. Prepared by JC Akwunwa

Use Quizgecko on...
Browser
Browser