WDF Manual
WDF Manual
PRACTICAL-1
Introduction:-
➢ Laravel is a free and open-source PHP web framework, created by Taylor Otwell
and intended for the development of web applications following the model–view–
controller architectural pattern and based on Symfony.
➢ Laravel is an easy-to-use web framework that will help you create extensible PHP-
based websites and web applications at scale.
Installation:-
Step 2: Visit this website using any web browser. Click on Composer-Setup.exe.
1
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
Step 5: Allow the permission and in Installation Option, don’t forget to click on ‘Developer
mode’ checkbox. Then ‘next’.
2
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
Step 6: Then select the destination path for composer. And click on ‘next’
Step 7: In Settings Check, Choose the command line PHP that u want to use. The PHP will be
given in your xampp file when you download your xampp in the PC. Then click on ‘next’.
3
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
Step 10: You will get a confirmation of ‘Completing composer Setup’. Click ‘Finish’ to
complete the setup.
Step 11: After the Composer is installed, check the installation by typing the Composer
command in the command prompt as shown in the following screenshot.
4
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
Step 12: Create a new directory anywhere in your system for your new Laravel project. After
that, move to path where you have created the new directory and type the following command
there to install Laravel.
5
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
Step 13: Installation of version 5.7. In Laravel version 5.7, you can install the complete
framework by typing the following command
Step 15: After executing the above command, you will see a screen as shown below
Step 16: Copy the URL underlined in gray in the above screenshot and open that URL in the
browser. If you see the following screen, it implies Laravel has been installed successfully.
We will See this welcome plate after searching the url.
6
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
Output:-
7
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
Output:-
8
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
PRACTICAL-2
➢ Database migration in Laravel allows you to define database schema and manipulate it
through PHP code rather than SQL queries directly. This provides a more consistent and
version-controlled way to manage your database structure.
➢ Let's say we want to create a ‘diya’ table
➢ Create a migration file using Artisan CLI
➢ Open the generated migration file (located in database/migrations) and define the schema
in the up() method:
Code:-
9
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
10
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
➢ Eloquent is Laravel's built-in ORM that allows you to interact with your database tables
using PHP syntax.
➢ Let's create a corresponding Eloquent model for the diya table
➢ Generate the model using Artisan CLI
➢ Open the generated model file (located in app/Models/diya.php) and define the table
name and any relationships:
11
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
➢ Define the schema for the posts table in the migration file and the corresponding
properties in the Post model.
12
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
Code:-
OUTPUT:
13
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B.Tech-IT Semester-6th Year-3rd
14
Enrollment No - 210303108064
Faculty of Engineering & Technology
Subject Name: WDF Laboratory
Subject Code:
B. Tech: IT Year: 3rd Semester:6th
Practical – 3
Aim: Build a REST API with Laravel.
Enrollment No.:2303031089001
Faculty of Engineering & Technology
Subject Name: WDF Laboratory
Subject Code:
B. Tech: IT Year: 3rd Semester:6th
Enrollment No.:2303031089001
Faculty of Engineering & Technology
Subject Name: WDF Laboratory
Subject Code:
B. Tech: IT Year: 3rd Semester:6th
Develop Controllers:
Create a controller to handle API logic:
php artisan make:controller ItemController –api
Enrollment No.:2303031089001
Faculty of Engineering & Technology
Subject Name: WDF Laboratory
Subject Code:
B. Tech: IT Year: 3rd Semester:6th
Testing:
Use tools like Postman to test your API endpoints for CRUD operations.
Enrollment No.:2303031089001
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code:203108484
B.Tech: IT Year: 3rd Semester: 6th
Practical-4
The route is a way of creating a request URL for your application. These URLs do not have
to map to specific files on a website, and are both human readable and SEO friendly.
In Laravel, routes are created inside the routes folder. They are created in the web.php file
for websites. And for APIs, they are created inside api.php.
a) Displaying a view
b) Authentication
Laravel provides built-in authentication scaffolding to quickly set up user authentication. Here's
how to implement it:
Step 3 : Open Admin panel of Mysql (It will redirect to localhost/phpmyadmin in browser)
Step 4 : Create new database with name "laravel"
Step 5 : Open your project folder "migration" in VScode and go to .env file
Step 6 : Search for DB_DATABASE and give the name of your database
(DB_DATABASE= laravel)
Step 7 : Open New terminal and run command " php artisan make:migration create_mytable "
It will create a new file in database/migrations folder
Route::get('/task-create',[TaskController::class,"create"]);
Route::post('/task-save',[TaskController::class,"store"]);
Route::get('/task-read',[TaskController::class,"show"]);
Route::get('/task-edit/{id}',[TaskController::class,"edit"]);
Conclusion:
By following the steps outlined in this manual, one should now have a good understanding of
how to implement routing in Laravel, display views, set up authentication, and create
controllers for managing tasks. Experiment further with Laravel's rich feature set to build
robust web applications efficiently.
Practical-5
When you're structuring a web application, having a consistent layout across multiple pages is
crucial for maintaining a cohesive user experience. In Laravel, this is achieved through the
concept of layouts.
1] Create Layout File: The layout file, often named something like master.blade.php, serves as
a blueprint for the structure shared among various pages of your application. This file resides
within the resources/views/layouts directory. It contains the foundational HTML structure,
including common elements like headers, footers, navigation bars, and any necessary CSS or
JavaScript includes.
Within the layout file, you'll use Blade directives such as @yield('section_name') to define
placeholders for dynamic content. These placeholders allow child views to inject specific
content into predefined sections of the layout.
1]Create Child View File: Child view files, such as about.blade.php, are created within the
resources/views directory.
These files extend the layout by utilizing the @extends('layouts.master') directive, where
'layouts.master' refers to the path of the layout file relative to the views directory.
Within the child view file, you define the specific content for the page using Blade directives
such as @section('section_name') and @endsection. These sections correspond to the
placeholders defined in the layout file and allow you to inject content unique to each page.
Once you've established the layout and defined child views, integrating them into your
application involves routing requests and rendering the appropriate views.
1] Define Route: In Laravel, routes are defined in the routes/web.php file. Each route specifies
a URL pattern and a corresponding action to be taken when that URL is accessed. Typically,
these actions return views, allowing you to dynamically render content based on the requested
URL.
For example, you might define a route like Route::get('/', function () { return view('home'); });.
This route instructs Laravel to render the home.blade.php view when the user visits the root
URL of your application.
2] Access the Page: Users interact with your application by navigating to its URLs in their web
browsers. When a user accesses a URL that matches a defined route, Laravel renders the
associated view. This process involves injecting the content of the child view into the
placeholders defined within the layout, resulting in a complete HTML response sent back to
the user's browser.
Conclusion:
By implementing layouts and child views in Laravel, you establish a structured approach to
building web applications that promotes code reusability, maintainability, and scalability. The
separation of concerns between layout and content allows for efficient development and easier
management of complex applications as they evolve over time. Additionally, the flexibility
provided by Blade directives enables you to create dynamic and engaging user experiences
while maintaining a consistent visual identity across your application.
Practical:06
Aim: Implement adding tasks, displaying existing tasks and deleting tasks with
code in Laravel.
1. Database Setup:
• Create a migration to define a tasks table:
2. Task Model:
• Create a model for Task:
3. Task Controller:
• Create a controller for managing tasks:
Enrollment N0.:2303031089001
Faculty of Engineering & Technology
Subject Name: WDF Laboratory
Subject Code:
B. Tech: IT Year: 3rd Semester:6th
Enrollment N0.:2303031089001
Faculty of Engineering & Technology
Subject Name: WDF Laboratory
Subject Code:
B. Tech: IT Year: 3rd Semester:6th
Enrollment N0.:2303031089001
Faculty of Engineering & Technology
Subject Name: WDF Laboratory
Subject Code:
B. Tech: IT Year: 3rd Semester:6th
Enrollment N0.:2303031089001
Faculty of Engineering & Technology
Subject Name: WDF Laboratory
Subject Code:
B. Tech: IT Year: 3rd Semester:6th
Practical:08
Aim: Authentication with Laravel
Laravel provides built-in authentication scaffolding to quickly set up user authentication. Here's how to
implement it:
Step 3 : Open Admin panel of Mysql (It will redirect to localhost/phpmyadmin in browser)
Step 4 : Create new database with name "new_demo"
Enrollment N0.:2303031089001
Faculty of Engineering & Technology
Subject Name: WDF Laboratory
Subject Code:
B. Tech: IT Year: 3rd Semester:6th
Step 5 : Open your project folder "migration" in VScode and go to .env file
Step 6 : Search for DB_DATABASE and give the name of your database
(DB_DATABASE= laravel)
Step 7 : Open New terminal and run command " php artisan make:migration create_mytable "
It will create a new file in database/migrations folder
Step 8 : run command "php artisan migrate"
Enrollment N0.:2303031089001
Faculty of Engineering & Technology
Subject Name: WDF Laboratory
Subject Code:
B. Tech: IT Year: 3rd Semester:6th
Enrollment N0.:2303031089001
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B. Tech: IT Year: 3rd Semester: 6 th
Practical:07
Aim: Process Payments with Stripe and Laravel Cashier
Procedure:-
To configure Laravel Cashier, follow the steps below:
$subscription = $user->subscription('default');
$subscription->cancel();
return redirect()->route('home');
})->name('cancel');
EXAMPLE:
Code:
\Stripe\Stripe::setApiKey(config('services.stripe.secret'));
$paymentMethod = $request->payment_method;
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => $amount,
'currency' => 'usd',
'payment_method_types' => ['card'],
'payment_method' => $paymentMethod,
'confirm' => true,
]);
if ($paymentIntent->status === 'succeeded') {
// Payment has been processed successfully
// You can create an order, update your database, or send a
confirmation email
// For example, to create a new order:
$order = Order::create([
'user_id' => $user->id,
'amount' => $amount,
'payment_intent_id' => $paymentIntent->id,
'status' => 'completed',
]);
// Redirect the user to a success page or display a confirmation
message
} else {
// Payment was not successful. You can handle the error or display
a message to the user
}
We first set the Stripe API key to the secret key provided in the .env file. We then
create a new payment intent using the payment_method obtained from the request.
Once the payment intent has been created, we can check its status to see if the
payment was successful. If the payment was successful, we can create a new order
or update the database accordingly. If the payment was not successful, we can
handle the error or display a message to the user.
Note that you need to have the stripe package installed in your Laravel project.
You can install it using composer:
Command :- composer require stripe/stripe-php
Also, make sure that you have configured the .env file with your Stripe API keys
and other required settings.
OUTPUT:-
Scenario 1: Payment Succeeded
Practical:09
Aim: Demonstrate How It Has Made: Laravel Router
Step 1:
Create a Controller
First, let's create a controller that will handle the incoming requests. In your
terminal, run the following command to generate a controller:
php artisan make:controller MyController
Step 2:
Define Routes
Next, you need to define routes in the ‘routes/web.php’ file. Open the file
and define your routes. Here's an example:
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\MyController;
Route::get('/hello', [MyController::class, 'hello']);
Route::get('/goodbye', [MyController::class, 'goodbye']);
Step 3:
Implement Controller Methods
Now, let's implement the methods in the MyController controller. Open
MyController.php in the app/Http/Controllers directory and define the hello
and goodbye methods:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class MyController extends Controller
{
public function hello()
{
return "Hello, World!";
}
public function goodbye()
{
return "Goodbye, World!";
}
}
Step 4:
Run the Application
That's it! You have created a basic router in Laravel. Now, you can run your
Laravel application using the following command:
php artisan serve
OUTPUT:-
Practical:10
Aim: Build a CMS with Larevel.
Step 1:
• Setting up laravel
composer create-project --prefer-dist laravel/laravel cms
• Configure Database: Update the ‘.env’ file with your database credentials.
• Create Database Tables: Use Laravel migrations to define your
database schema.
php artisan make:migration create_posts_table
• Update the migration file with the necessary columns and then run:
php artisan migrate
Step 2: Authentication.
• Install Laravel UI (Optional): Laravel UI provides a simple way to
scaffold authentication and frontend components.
composer require laravel/ui
php artisan ui vue --auth
npm install && npm run
dev
Enrollment No.:2303031089003
Faculty of Engineering & Technology
Subject Name: WDF LAB
Subject Code: 203108484
B. Tech: IT Year: 3rd Semester: 6th
OUTPUT:-
Exampole (Build blogs + CMS).
Enrollment No.:2303031089003