Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views20 pages

Web Application Development (SEN 305) - Week 2

This document provides an overview of the Laravel framework used for web application development, detailing its benefits, setup requirements, and project structure. It includes instructions on creating a Laravel project, navigating the command prompt, and utilizing the artisan command for server management. Additionally, it outlines the assignment for students to create and run their own Laravel project for inspection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views20 pages

Web Application Development (SEN 305) - Week 2

This document provides an overview of the Laravel framework used for web application development, detailing its benefits, setup requirements, and project structure. It includes instructions on creating a Laravel project, navigating the command prompt, and utilizing the artisan command for server management. Additionally, it outlines the assignment for students to create and run their own Laravel project for inspection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Week 2

Web Application
Development (SEN
305)
• Software Engineering,
• Department of Computing Science,
• Faculty of Science,
• Admiralty University of Nigeria (ADUN),
• Delta State.

Lecturer: Bernard Ephraim


Laravel Framework
What is Laravel?
 Laravel is simply a web app framework for the PHP programming language.
 As with other web frameworks, it follows the MVC architecture.
Benefits of Using Laravel
 Provides a rich framework to facilitate the creation of forms and the manipulation of form data.
 Provides components and tools to help you in the development and testing of Laravel applications.
 Automated admin interface.
 Provides multiple protection tools and mechanisms for optimum web app security.
 There are a variety of techniques and tools that can help get your code running more efficiently - faster,
and using fewer system resources.
 Offers good dependencies management.
 It is free to use
Getting Started With Laravel
 Before creating your first Laravel project, you should ensure that your local machine has the latest version of
PHP and Composer installed.
 One easy way to get PHP onto your machine is to install WAMP or XAMPP server.
 Download
 WAMP here (https://sourceforge.net/projects/wampserver/) and
 XAMPP here (https://www.apachefriends.org/).
 Remember that PHP is the base programming language for Laravel.
 WAMP or XAMPP server helps to provide us with PHP and MySQL database that would be useful for our work.
 Download and install composer here (https://getcomposer.org/Composer-Setup.exe).
 Composer is the PHP package manager (similar to PIP for python, NPM for nodejs) used by Laravel to ensure
that all libraries used in the framework are up to date.
Using the Command Prompt with PHP Compiler
 In order to use Laravel and composer we need to know how to use the command prompt at least a little.
 Open windows command prompt by typing cmd in the search bar.
Import commands
 dir: lists the files and subdirectories (folders) in the current directory
 cd: changes the current directory to a new directory as specified,
 example C:\Users\BERNARD EPHRAIM>cd ../ changes current directory to C:\Users>
 cls: clears the screen
 mkdir: creates a new directory
 composer: allows us to install or update a library or framework
 php: allows us to run a php file or process from the command prompt
 php artisan: allows us to work with the Laravel frame work from the command line
 A short cut to setting a particular directory as your working directory would be to navigate to the folder using
the windows file explorer and then typing cmd in the address bar and pressing enter.
 Start visual studio code by typing code . in command prompt. Ensure it is installed first else this won’t work!
Creating a Laravel Project Laravel Project Directory
 To create a Laravel project, open command prompt
 Navigate to the folder (directory) where you want the project to be
installed.
 Type the following composer command composer create-project
laravel/laravel my-app
 Ensure you have a stable internet connection for the above to work.
 Wait for composer to download the instance of Laravel project and all
its dependencies.
 The output project folder looks like the figure to the right.
 Seven (7) folders and five (5) files are worthy of mention:
 Folders: app, database, public, resources, routes, storage, vendor
 Files: .env, artisan, composer.json, composer.lock, package.json
Inside Laravel Project Directory App Directory
 App Folder
 This folder contains other folders that hold the
Laravel app logic, commands and data models.
 Notable among them are:
 Console folder: contains code for console
(command-line) code, Laravel command and
schedule code.
 Http folder: contains the Controller and middleware
codes. Middleware are code used to intercept and
check some aspect of an incoming HTTP request
such as authentication validation and so on.
 Models folder: contains the models (blueprints) for
the Laravel app database tables. By default the
User.php model ships with every Laravel project.
 Models provide an interface for communicating with
the database from the Laravel project using the
Eloquent Object Relational Mapper (ORM).
Inside Laravel Project Directory
Database Directory
 Database Folder
 This folder contains other folders that hold the code
responsible for generating database tables,
prepopulating these tables with default values and
generating test cases fast.
 Notable among them are:
 Factories folder: contains code for quickly generating
test case data fast. By default the UserFactory.php
factory ships with every Laravel project.
 Migrations folder: contains the codes responsible for
the generation of database tables. These contains
the schema of the database making it seamless to
install database in a new environment. These files
are called migration files.
 Seeders folder: contains the code that help to
prepopulate the generated database with default
(initial) values necessary for the smooth kick-off of
the Laravel app.
Inside Laravel Project Directory
Public Directory
 Public Folder
 This folder receives all http requests to this
project and redirects to the appropriate logic.
Inside Laravel Project Directory
Resources Directory
 Resources Folder
 This folder contains other folders that hold the
code responsible for the front-end (user
interface) development.
 Notable among them are:
 CSS folder: contains code for stylesheets that
you may want to use.
 JS folder: contains the codes for JavaScript that
you have written for the project.
 Views folder: contains the HTML code. Laravel
uses an HTML template engine called blade.
Every blade file ends in filename.blade.php.
Inside Laravel Project Directory
Routes Directory
 Routes Folder
 This folder contains files that are used to specify
how an http request should be handled – this
entails passing the request to appropriate
controller and function handler.
 Notable among them are:
 api.php file: handles all requests to the API
route. API routes begin with /api/. To build a
rest API or a backend that can interact with
both web and mobile applications, use this
route.
 web.php file: handles all web requests not
made through the API route.
Inside Laravel Project Directory
.env File
 Storage Folder: used to hold static app
components like image files, videos etc
 Vendor Folder: holds all PHP installed packages
on this project.
 .env file: holds the environment variables for
this project. Environment variables helps us to
hide sensitive pieces of data (like password,
pins, authentication tokens) from the public
while sharing our code with other people.
 To the right are snapshots from the .env file
defining database and SMTP mailing variables.
 Environment variables are those in blue color
and usually written in upper case and the values
are those written in white.
Inside Laravel Project Directory
 Artisan file: is the command line tool for Laravel. It is used this way in the command prompt or
console: php artisan some_command
 Composer.json and composer.lock files: track the php dependencies installed in the vendor folder
by composer.
 Package.json file: used by Node Package Manager (NPM) to manage JavaScript dependencies.
Understanding the Artisan File and Commands
 The artisan file is the livewire of Laravel project. Without it the Laravel command-line is useless
and development process becomes almost impossible.
 To cut it short, new files, classes or Laravel components are created using the artisan file and
command.
 Now, open up the Laravel project in VS code.
 To do this open VS code
 Click file and click on open folder
 Select the project folder and click select
 To see what the artisan command is made of, type php artisan list in the VS code terminal
 You get the terminal
 Click on Terminal -> New Terminal in the menu bar or
 Use the ctrl + `
Running the Laravel Server
 The Laravel project can be made to come alive using the artisan command:
 Php artisan serve
 We get the following output

 Now, Laravel has started a development server for us on localhost (http://127.0.0.1:8000) and on
the default port 8000
 To define your port use php artisan serve –port=port_number
Running the Laravel Server
 To define a suitable host to run your server use php artisan serve –host=ip
 In the figure below host IP is 127.0.0.2

 Once a server is running on a terminal you cannot type on that terminal.


 To write other commands while the server runs, open a new terminal by clicking the plus (+) symbol to
the right hand side of the terminal window.
 To quit (or stop) a running server press ctlr + c.
Running the Laravel Server
 While your server runs copy the address displayed on the terminal and open it in a browser
 Your outcome should look like the figure below.
Assignment 1
 Create a new folder named sen305. In this folder create a Laravel project called yourname-
project.
 Run the Laravel server to ensure it is working well.
 Bring the project in your computer to class for inspection.
 Note: install all Laravel dependencies.
The End

You might also like