You are on page 1of 4

Cookies

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's
computer. Each time the same computer requests a page with a browser, it will send the cookie too.
With PHP, you can both create and retrieve cookie values.

Syntax
setcookie(name, value, expire, path, domain, secure, httponly);

Create Cookie
<!DOCTYPE html>

<?php

$cookie_name = "user";

$cookie_value = "John Doe";

setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day

?>

<html>

<body>

<?php

if(!isset($_COOKIE[$cookie_name])) {

echo "Cookie named '" . $cookie_name . "' is not set!";

} else {

echo "Cookie '" . $cookie_name . "' is set!<br>";

echo "Value is: " . $_COOKIE[$cookie_name];

?>

<p><strong>Note:</strong> You might have to reload the page to see the value of the cookie.</p>

</body>

Laravel
Where can we find/ create Laravel file
In Laravel folder, there is a folder resources with sub folder views. Save file there wit .blade.php
extension
Creating route
Route::get('/', function () {
return view('welcome');
});

Creating Controller
 Open cmd and change directory to Laravel folder path
cd C:\xampp\htdocs\Laravel\lar

 Create controller with command:


php artsan make:Controller controllerName

Use of Laravel:
Laravel is primarily used for building custom web apps using PHP. It's a web framework that handles
many things that are annoying to build yourself, such as routing, templating HTML, and
authentication.

What is Laravel?
Laravel is an open-source widely used PHP framework. The platform was intended for the
development of web application by using MVC architectural pattern. Laravel is released under the
MIT license.

Composer
It is an application-level package manager for PHP. It provides a standard format for managing PHP
software dependencies and libraries.

What is HTTP middleware?


HTTP middleware is a technique for filtering HTTP requests. Laravel includes a middleware that
checks whether application user is authenticated or not.

PHP LARAVEL ARTISAN SERVE


The Laravel PHP artisan serve command helps running applications on the PHP development server.
As a developer, you can use Laravel artisan serve to develop and test various functions within the
application. It also accepts two additional options. You can use the host for changing application’s
address and port. Meanwhile, you can also use the port option to change the port of the application.

What is a Route?
A route is basically an endpoint specified by a URI (Uniform Resource Identifier). It acts as a pointer
in Laravel application.
Most commonly, a route simply points to a method on a controller and also dictates which HTTP
methods are able to hit that URI.

Why use Route?


Routes are stored inside files under the /routes folder inside the project's root directory. By default,
there are a few different files corresponding to the different "sides" of the application ("sides" comes
from the hexagonal architecture methodology).

What are the advantages of using Laravel?


Here are important benefits of Laravel:
 Laravel has blade template engine to create dynamic layouts and increase compiling tasks.
 Reuse code without any hassle.
 Laravel provides you to enforce constraints between multiple DBM objects by using an
advanced query builder mechanism.
 The framework has an auto-loading feature, so you don't do manual maintenance and
inclusion paths
 The framework helps you to make new tools by using LOC container.
 Laravel offers a version control system that helps with simplified management of migrations.

Name databases supported by Laravel.


Laravel supports the following databases:

 PostgreSQL
 SQL Server
 SQLite
 MySQL

Laravel Directories
Console
Contains all your Artisan commands

Http
Contains all your controllers, middleware, requests, and routes file

Providers
Contains all your application service providers. You can read more about Service Providers here

Events
Contains all your event classes

Exceptions
Contains your application exception handler and custom exception classes

Jobs
Contains all the jobs queued by your application

Listeners
Contains all the handler classes for your events

Policies
Contains the authorization policy classes for your application. Policies are used to determine if a user
can perform a given action against a resource.

Explore Directory Structure


Laravel applications follow the Model-View-Controller design pattern.
 Models query your database and return the necessary data.
 Views are pages that render data
 Controllers handle user requests, retrieve data from the models, and pass them to the views.
Ajax
 AJAX = Asynchronous JavaScript And XML.
 AJAX is not a programming language.
 AJAX just uses a combination of:
 A browser built-in XMLHttpRequest object (to request data from a web server)
 JavaScript and HTML DOM (to display or use the data)

How Ajax works?


1. An event occurs in a web page (the page is loaded, a button is clicked)
2. An XMLHttpRequest object is created by JavaScript
3. The XMLHttpRequest object sends a request to a web server
4. The server processes the request
5. The server sends a response back to the web page
6. The response is read by JavaScript
7. Proper action (like page update) is performed by JavaScript

Operations can be performed with Ajax


 Update a web page without reloading the page
 Request data from a server - after the page has loaded
 Receive data from a server - after the page has loaded
 Send data to a server - in the background

You might also like