0% found this document useful (0 votes)
38 views19 pages

Laravel 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views19 pages

Laravel 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Difference betn JavaScript and ajax

JavaScript

 What it is:
A programming (scrip ng) language that runs in the browser.

 Purpose:
Used to make webpages interac ve (e.g., form valida on, anima ons, DOM manipula on).

 How it works:
Runs on the client side (in the browser).

document.getElementById("btn").onclick = func on() {

alert("Bu on clicked!");

};

AJAX (Asynchronous JavaScript and XML)

 What it is:
Not a language, but a technique that uses JavaScript + XML/JSON to communicate with the server
without reloading the page.

 Purpose:
To send/receive data from a server asynchronously and update parts of a webpage dynamically.

 How it works:
Uses XMLH pRequest (or fetch in modern JS) inside JavaScript.

fetch("h ps://jsonplaceholder.typicode.com/posts/1")

.then(response => response.json())

.then(data => {

document.getElementById("result").innerText = data. tle;

});

Aspect JavaScript AJAX

Type Programming language Technique/approach using JS

Usage Make webpages interac ve Fetch/send data asynchronously

Server Used specifically for server


Not required
Interac on communica on

Normal JS o en reloads AJAX avoids page reload, updates


Page Reload
pages for new data content dynamically

 JavaScript = the language.

 AJAX = a way of using JavaScript to talk to the server in the background.


What is eloqunt model

Eloquent Model in Laravel

 Eloquent is Laravel’s ORM (Object Rela onal Mapper).

 A Model in Laravel represents a table in your database.

 Each row of that table is represented as a Model object.

Suppose you have a table users.


You create a model User.php:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class User extends Model

Fetch all users :- $users = User::all();

Find one user by id :- $user = User::find(1);

Insert new user :- $user = new User();

$user->name = "Jaymin";

$user->email = "[email protected]";

$user->save();

Update user :- $user = User::find(1);

$user->name = "Updated Name";

$user->save();

Delete user :- User::destroy(1);

An Eloquent model is just a PHP class in Laravel that connects to a database table and makes it easy
to insert, read, update, delete records without wri ng raw SQL.

Eloquent Model (Laravel)

 It’s like a bridge between your database table and your Laravel code.

 Each model = 1 table in the database.

 You use the model to insert, read, update, delete data — without wri ng SQL.

In short:
Eloquent model = PHP class that makes working with a database easy like talking to objects.
What is mvc and how it work

1. Model (M)

 Works with the database.

 Example: A User model gets data from the users table.

$users = User::all();

2. View (V)

 The front-end / UI (what user sees).

 Example: Blade file users.blade.php shows the list of users.

<h1>User List</h1>

@foreach($users as $user)

<p>{{ $user->name }}</p>

@endforeach

3. Controller (C)

 The middleman between Model and View.

 Takes request → asks Model for data → sends data to View.

class UserController extends Controller {

public func on index() {

$users = User::all(); // get data from Model

return view('users', compact('users')); // send to View

How it works (Step by Step)

1. User clicks URL → Request goes to Controller.

2. Controller asks Model for data.

3. Model talks to the database and returns the data.

4. Controller sends data to the View.

5. View shows it to the user in browser.

In short:

 Model = Database

 View = UI (frontend)

 Controller = Boss (manages flow between Model & View)


MVC = Model – View – Controller

 Model (M) → Works with database (get, save, update data).

 View (V) → The frontend/UI (what user sees).

 Controller (C) → The middleman (takes request, talks to Model, sends data to View).

How it works (example in daily life):

Suppose you order food in a restaurant:

 You (User) → make a request (order food).

 Waiter (Controller) → takes your order and tells the kitchen.

 Kitchen (Model) → prepares food (fetches data).

 Waiter (Controller) → brings food to you.

 You see the food (View) → output shown on screen.

In short:

 Model = Database

 View = What you see

 Controller = Messenger between them

At a Glance: Laravel 11 vs Laravel 12 Diffrence

Feature / Aspect Laravel 11 (Released March 12, 2024) Laravel 12 (Released February 24, 2025)

PHP Version
PHP 8.2 – 8.4 (Laravel, kri myantra.com) PHP 8.2 – 8.4 (Laravel, kri myantra.com)
Required

Slim skeleton, streamlined folder Minor release focused on enhancements,


Release Focus structure, op mized defaults (Laravel, dependency updates, developer tools
Laravel Daily) (Laravel, Laravel Daily, Bacancy)

New official starter kits for Vue, React, and


Tradi onal structure; added Ar san
Starter Kits / Livewire with Tailwind, TypeScript,
commands like make:enum, make:class
Scaffolding shadcn/ui, and WorkOS AuthKit (Laravel,
(Laravel Daily, Laravel)
Bacancy, Wikipedia)

Architecture & Slimmer skeleton: consolidated Further refinement and improved project
Structure bootstrap/app.php, removed organiza on (Bacancy)
Feature / Aspect Laravel 11 (Released March 12, 2024) Laravel 12 (Released February 24, 2025)

app/Excep ons, Middleware, etc.


(Laravel Daily, Laravel)

General improvements; introduced Op mized rou ng, caching, and background


Performance &
Laravel Reverb WebSocket server processing for be er speed and scalability
Rou ng
(Laravel, Laravel Daily) (Medium, kri myantra.com, Bacancy)

API and broadcas ng installed GraphQL support, API versioning, improved


APIs &
op onally; new defer() queue helper WebSockets, AI-powered debugging
Authen ca on
(Laravel Daily, Laravel, kri myantra.com) assistant (Bacancy)

New Ar san commands (make:enum, AI debugging with debug()->suggest(),


Developer
etc.), health route /up, Slim defaults smarter Ar san CLI, be er IDE support
Experience
(Laravel Daily, Laravel) (Bacancy, Medium)

Minimal breaking changes; upgrade mostly


Breaking Changes & Moderate breaking updates; new
smooth with few adjustments (Laravel,
Upgrade Impact skeleton but easy to adapt (Laravel Daily)
Laravel Daily, kri myantra.com)

Bug fixes: un l August 13, 2026 Security


Support Timeline Bug fixes: un l Sept 3, 2025 Security
fixes: un l February 24, 2027 (Laravel,
(Bug/Security Fixes) fixes: un l March 12, 2026 (Laravel)
kri myantra.com)

Highlights of Laravel 12

 Starter Kits for modern front-ends: Official scaffolding for React, Vue, and Livewire with Tailwind,
TypeScript, and shadcn/ui—plus op onal WorkOS AuthKit for social logins, passkeys, and SSO.
LaravelBacancyWikipedia

 AI-powered debugging: Use debug($var)->suggest() to get real- me insights and possible fixes.
Bacancy

 API enhancements: Na ve GraphQL support and cleaner API versioning syntax. Bacancy

 Performance tweaks: Improved caching, faster route handling, be er job processing, and memory
op miza ons. BacancyMedium

 Real- me & WebSocket improvements: Smoother event broadcas ng and lower-latency WebSocket
handling. Bacancy

In short:

 Laravel 11 = big cleanup + new structure.

 Laravel 12 = polish, performance, new starter kits, AI debugging.

Laravel 11 me kya nikala / badla

 app/Excep ons, app/H p/Middleware, app/Providers folders → nikal diye (ab default me nahi
milte).

 bootstrap/app.php → abhi isi file se pura project boot hota hai (pura simple kar diya).
 auth, broadcas ng, queue ka pura setup default me nahi aata → aapko chahiye to install karna
padta hai.

 Route middleware list bhi slim kar di (sirf zaroori reh gaye).

Laravel 12 me kya naya / change

 Naya starter kit → Vue, React, Livewire + Tailwind + TypeScript + shadcn/ui.

 AI debugging → debug()->suggest() se error ke solu on milte hain.

 GraphQL + API versioning → API banane me easy.

 Performance be er → fast rou ng, caching, background jobs.

 Support lamba (2027 tak security fixes).

  Laravel 11 = purana extra code nikala, project ko clean/simple banaya.


  Laravel 12 = naye tools aur performance add kiye, AI debugging, starter kits,
GraphQL.

Laravel 11 vs Laravel 12

Laravel 11 (2024)

 Made project structure simpler (less files, cleaner).

 Added new Ar san commands (make:enum, etc.).

 Introduced Laravel Reverb (WebSockets).

 Be er defaults for queues, excep ons, and health check.

Laravel 12 (2025)

 Not big changes → more like improvements.

 New starter kits (Vue, React, Livewire) with Tailwind + TypeScript.

 AI debugging → debug()->suggest() helps find issues.

 Faster rou ng, caching, background jobs.

 Added GraphQL + API versioning support.

 Longer support ( ll 2027).

I USED LARAVEL 10 AND PHP 8.2-8.3-8.4


DIFFRence betn api and res ul api

API (Applica on Programming Interface)

 API ka matlab: Rules aur methods ka set jisse ek so ware doosre so ware se baat kar sake.

 API alag–alag tarike ke hote hain → SOAP API, GraphQL API, REST API, etc.

 Example:

o Weather API → “Mujhe Ahmedabad ka temperature batao.”

o Google Maps API → “Loca on data do.”

RESTful API

 REST = Representa onal State Transfer (ek style / architecture hai).

 RESTful API = API jo REST rules follow kar hai.

 Ye HTTP methods ka use kar hai:

o GET → Data lana

o POST → Data create karna

o PUT/PATCH → Data update karna

o DELETE → Data delete karna

 Aur ye resources ko URL ke through represent kar hai.

 Example:

o GET /users → sab users ka data do

o POST /users → naya user banao

o PUT /users/1 → user 1 update karo

o DELETE /users/1 → user 1 delete karo

API RESTful API

General term → kisi bhi interface ko keh sakte hain jo Ek specific type of API jo REST principles follow
so ware ko connect kare. kar hai.

Ho sakta hai SOAP, GraphQL, gRPC, REST, etc. Sirf REST architecture par based ho hai.

Rules fixed hote (HTTP methods, stateless,


Rules fix nahi hote.
resources via URL).

In short:

 API = ek general concept (so ware communica on ka tareeka).

 RESTful API = ek special type of API jo REST rules follow kar hai.
mysql and sql different

SQL (Structured Query Language)

 Ye ek language hai jo database se baat karne ke liye use ho hai.

 Iska kaam hai: data create, read, update, delete karna (CRUD).

 Example SQL commands:

SELECT * FROM users; -- data lana

INSERT INTO users (name, email) VALUES ('Jaymin', '[email protected]'); -- data add karna

MySQL

 Ye ek Database Management System (DBMS) hai.

 MySQL ke andar data tables me store hota hai.

 MySQL ko chalane ke liye hum SQL language ka use karte hain.

SQL MySQL

Ek database so ware hai jisme


Ek language hai (query likhne ke liye).
data store hota hai.

Standard hai → sab DBMS (Oracle, SQL Server, Sirf ek DBMS hai jo SQL use
PostgreSQL, MySQL) SQL ko samajhte hain. karta hai.

Data ko tables me store karta


Khud data store nahi karta.
hai.

 SQL = Language (jaise English).

 MySQL = Database so ware (jaise ek library jo English samajh hai).

School Example

1. MySQL (Database so ware)

Socho school ke paas ek Almirah (database) hai jisme sari files aur tables (students, teachers, classes) rakhi
ho hain.

 Ye Almirah hi MySQL hai → data ko safe store karta hai.


2. SQL (Language)

Ab teacher ko students ki list chahiye.

 Teacher English ya Hindi me bolkar order karega → lekin database sirf SQL language samajhta hai.

 Hum query likhte hain:

SELECT * FROM students;

Ye SQL command MySQL ko bolta hai → “students wali file kholo aur sab data dikhao.”

Summary

 MySQL = Store (Almirah/Library)

 SQL = Language (jo order dene ke liye use ho hai)

Matlab, MySQL bina SQL ke samajh nahi sakta


aur
SQL apne aap data store nahi kar sakta.

what is laravel and its benefit

What is Laravel?

 Laravel ek PHP framework hai.

 Framework = ready-made tools + rules jisse aap web applica ons fast aur secure bana sakte ho.

 Ye MVC pa ern follow karta hai (Model–View–Controller).

Benefits of Laravel

1. Fast Development → Bahut saare built-in features (auth, rou ng, queues) → coding kam, speed
zyada.

2. MVC Support → Code clean, easy to manage, aur alag-alag part handle karna simple.

3. Database Eloquent ORM → Direct PHP code se database access (SQL likhne ki need kam).

4. Security → CSRF protec on, password hashing, input valida on.

5. Blade Templa ng → Easy aur fast UI banane ke liye templa ng engine.

6. Ar san CLI → Command line se migra ons, models, controllers create karna easy.

7. Community Support → Laravel ka documenta on + community bohot strong hai.

8. Scalable → Chho websites se lekar bade enterprise apps tak ke liye use ho sakta hai.
9. In short:

Laravel = PHP framework jo web app banane ko easy, fast aur secure banata hai.

E-commerce Website with Laravel

1. Authentication (Login/Signup)

 Laravel me ready-made Auth system hai.


 Example: Customer account banata hai ya login karta hai.
 Laravel handle karega: password hashing, session, security tokens.

2. Product Management (Database + Eloquent ORM)

 Products table → MySQL me data store.


 Laravel ka Eloquent Model use karke easily data fetch/update kar sakte ho:

$products = Product::all();

3. Shopping Cart (Controller Logic)

 User product add karta hai → Controller data manage karega.


 Example: CartController → add, remove, checkout ka kaam karega.

4. Order System (MVC Flow)

 Model → Order table me order save hota hai.


 Controller → order create karta hai.
 View → customer ko “Order Placed Successfully” message dikhata hai.

5. Blade Templating (Frontend)

 Laravel ka Blade engine use karke simple aur dynamic UI ban jaata hai.

@foreach($products as $product)

<p>{{ $product->name }} - ₹{{ $product->price }}</p>

@endforeach

6. Security

 CSRF protection → checkout form safe.


 SQL Injection safe → Eloquent queries automa cally protected.
7. Payment Integration

 Laravel ke ecosystem me ready packages hote hain (Stripe, Razorpay, PayPal).


 Isse payment gateway easily connect ho jaata hai..

Summary with Example

 Laravel ke saath aap ek E-commerce app bana sakte ho jisme:


o Login/Signup ready hai,
o Products database se aate hain,
o Cart aur orders easy manage hote hain,
o Secure checkout hota hai,
o Payment gateway integrate karna easy hai.

Laravel Core PHP


Ready-made framework with tools (auth,
Sab kuch manually likhna padta hai.
routing, DB, security).
Code messy ho sakta hai (mix of HTML +
Code organized (MVC).
PHP).
Development slow & risky (security
Development fast & secure.
manually karni hoti hai).
Laravel CodeIgniter
Modern framework, rich features (Eloquent
Lightweight, fast, but limited features.
ORM, Blade, Queues, Events).
Big community + ecosystem. Smaller ecosystem.
More opinionated (fix structure follow karna
Flexible, less strict.
padta hai).

Laravel Symfony
Easy to learn, beginner friendly. Complex, enterprise-level framework.
Many built-in features (auth, queue, broadcasting). Very powerful, but setup/config zyada.
Faster development for small/medium apps. Best for very large apps (banks, ERPs).

Laravel Yii
Popular, modern syntax, Blade templating. Focus on high performance, caching.
Rich ecosystem (Breeze, Jetstream, Nova, Built-in tools strong, but smaller
Horizon). community.
More active community & tutorials. Less popular compared to Laravel.
In short

 Laravel = Modern, beginner-friendly, feature-rich framework (best balance).


 CodeIgniter = Simple & lightweight, but less features.
 Symfony = Heavy, enterprise-level, very powerful.
 Yii = Performance-focused, but less community.
 Core PHP = No rules, sab manual karna padta hai.

Matlab:
Agar tum fast development, security, aur community support chahte ho → Laravel best
choice hai.

jQuery kya hai?

 jQuery ek JavaScript library hai.


 Matlab: JavaScript ka ready-made code collection jo short aur easy syntax deta hai.
 Use karke aapko kam code likhna padta hai aur browser compatibility ka tension
nahi hota.

jQuery se kya kar sakte ho?

1. DOM Manipulation (HTML change karna, hide/show elements).


2. Events handle karna (button click, hover, etc.).
3. Animations (fade, slide, toggle).
4. AJAX calls (server se data lana bina page reload).
5. Cross-browser support (har browser me code same chalega).

Example without jQuery (Plain JS):

document.getElementById("btn").addEventListener("click", function() {

document.getElementById("msg").style.display = "none";

});
jQuery = JavaScript ka shortcut library jo coding ko easy aur fast banata hai (specially purane me
me jab JS aur browser support weak tha).
Same Example with jQuery:

$("#btn").click(function() {

$("#msg").hide();

});

how many laravel already bulitin package and use

Laravel ke andar already bohot saare official packages milte hain jo alag-alag purpose ke
liye use hote hain.

Main Built-in / Official Laravel Packages

1. Laravel Breeze

 Simple starter kit for Auth (login, register, reset password).


 Lightweight (Blade, Vue, React, Inertia, Livewire support).

2. Laravel Jetstream

 Advanced starter kit (teams, sessions, 2FA, API tokens).


 Built on top of Breeze + Livewire/Inertia.

3. Laravel Sanctum

 For API authentication (single-page apps, mobile apps).


 Easy alternative to OAuth.

4. Laravel Passport

 Full OAuth2 authentication system.


 Best for large apps with third-party integrations.

5. Laravel Cashier

 Subscription billing integration (Stripe & Paddle).


 Manage payments, subscriptions, invoices.

6. Laravel Scout

 Full-text search for models.


 Works with drivers like Algolia, Meilisearch.

7. Laravel Socialite

 OAuth login via Google, Facebook, Twitter, GitHub, etc.

8. Laravel Horizon

 Dashboard & monitoring for queues (Redis).

9. Laravel Telescope

 Debug assistant → request logs, queries, excep ons, jobs monitoring.

10. Laravel Dusk

 Browser automation & testing (like Selenium).

11. Laravel Sail

 Docker environment for running Laravel locally.

12. Laravel Pint

 Official PHP code style fixer (based on PHP-CS-Fixer).

13. Laravel Envoy

 Task automation & deployment tool (like Ansible/Capistrano).

14. Laravel Reverb (new in v11)


 Official WebSocket server for real-time apps.

Summary

Laravel ke paas dozens of official packages hote hain, lekin ye sabse popular aur widely
used 12–14 packages hain:

 Auth → Breeze, Jetstream, Socialite


 API Security → Sanctum, Passport
 Payment → Cashier
 Search → Scout
 Queues → Horizon
 Debugging/Testing → Telescope, Dusk, Pint
 Dev Tools → Sail, Envoy
 Real-time → Reverb

Package Name Use Case / Purpose


Breeze Simple auth (login, register, reset password) starter kit
Jetstream Advanced auth (teams, sessions, 2FA, API tokens)
Sanctum API authentication for SPAs & mobile apps
Passport Full OAuth2 authentication system
Cashier Subscription billing & payments (Stripe, Paddle)
Scout Full-text search for Eloquent models
Socialite Login via Google, Facebook, GitHub, etc.
Horizon Dashboard + monitoring for queues (Redis)
Telescope Debugging: requests, queries, exceptions, jobs
Dusk Browser testing & automation (like Selenium)
Sail Local dev environment using Docker
Pint Official PHP code style fixer
Envoy Task automation & deployment tool
Official WebSocket server for real-time apps

Reverb (v11+)

Quick Memory Tip


 Auth → Breeze, Jetstream, Socialite
 API Security → Sanctum, Passport
 Payment → Cashier
 Search → Scout
 Queues → Horizon
 Debugging/Testing → Telescope, Dusk, Pint
 Dev Tools → Sail, Envoy
 Real-time → Reverb

Any command ya package hai ?that which can be direct crud operation with ajax fn

1. Laravel DataTables (Yajra Package)

 Sabse famous package for AJAX-based CRUD + tables.


 Data ko JSON me load karta hai, sorting, searching, pagination AJAX ke through
hoti hai.
 CRUD ke liye backend Laravel ke controllers/models use hote hain.

composer require yajra/laravel-datatables-oracle

return datatables()->of(User::query())->make(true);

2. Laravel Livewire (No AJAX Code Needed)

 Agar tum AJAX manually likhna avoid karna chahte ho → Livewire best op on hai.
 Ye internally AJAX hi use karta hai, but tumhe JavaScript likhne ki zaroorat nahi
hoti.
 Example: CRUD forms bina JS likhe reactive ho jaate hain.

Install:

composer require livewire/livewire

3. Inertia.js (Vue/React + Laravel)

 Laravel ke backend ke saath Vue ya React use karke single-page app banata hai.
 Ye bhi AJAX hi use karta hai, lekin modern SPA style me.

4. Scaffolding Packages (CRUD Generators)

Agar tumhe sirf CRUD code auto-generate karna hai (with AJAX support), to ye packages
help karte hain:
 InfyOm Laravel Generator → CRUD + API + AJAX support.
 Laravel Code Generator (CrestApps) → Models, controllers, views auto generate.

In Short

 Direct AJAX CRUD → yajra/laravel-datatables


 AJAX bina JS likhe → Livewire
 Modern SPA style → Iner a.js
 Full CRUD auto generate → InfyOm or CrestApps Code Generator

Middle ware kya hai aur uska use batao, realtime ex

Middleware Kya Hai?

Middleware ek filter hota hai jo request aur response ke beech me kaam karta hai.
Socho user jab Laravel app ko request bhejta hai → pehle middleware check karega, phir
controller tak request jayegi.

Middleware ka Use

1. Authentication check → user login hai ya nahi.


2. Role check → sirf admin hi kuch pages access kar sake.
3. Security → CSRF, XSS, request headers check karna.
4. Logging → request ka log maintain karna.
5. Localization → language set karna (Hindi/English).

Middleware kya hai?

 Laravel me Middleware ek filter ki tarah kaam karta hai.


 Ye request ko controller tak pahunchne se pehle check karta hai.
 Agar condition pass ho gayi → request aage jaayegi.
 Agar fail ho gayi → turant block kar dega ya redirect karega.
Realtime Example

Example 1: Login Check Middleware

 User /dashboard open karta hai.


 Middleware check karega → kya user login hai?
o Agar login hai → dashboard show.
o Agar login nahi hai → login page par redirect.
o
 Route::middleware('auth')->group(function () {
 Route::get('/dashboard', [DashboardController::class, 'index']);
 });

Example 3: Localization Middleware

 User ke browser me Hindi set hai → Middleware app ki language Hindi kar dega.
 Dusre user ke liye English hi chalegi.

Middleware = Gatekeeper

 Jo request aane par check karta hai → allow karni hai ya rokni hai.

Type Description Example


Har request pe
Global
automatically run hota \App\Http\Middleware\TrustProxies
Middleware
hai
Route Specific route ya group
auth, role:admin
Middleware me lagaya jaata hai
Middleware Multiple middleware ek
web (session, CSRF), api (throttle)
Groups saath apply karna

ss

You might also like