0% found this document useful (0 votes)
3 views

PHP Frameworks

The document provides a comprehensive overview of PHP frameworks, specifically Laravel, and its MVC architecture. It covers key concepts such as creating projects, defining routes, using Blade syntax, and performing CRUD operations with Eloquent ORM. Additionally, it touches on the Semantic Web, RDF, and hosting Laravel projects on cPanel.

Uploaded by

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

PHP Frameworks

The document provides a comprehensive overview of PHP frameworks, specifically Laravel, and its MVC architecture. It covers key concepts such as creating projects, defining routes, using Blade syntax, and performing CRUD operations with Eloquent ORM. Additionally, it touches on the Semantic Web, RDF, and hosting Laravel projects on cPanel.

Uploaded by

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

🔹 PHP Frameworks & MVC Architecture (Q1–Q5)

1. What is MVC? Demonstrate with a diagram or explanation.

Explanation:
MVC (Model-View-Controller) is a design pattern that separates logic:

 Model: Handles data (DB).

 View: User interface.

 Controller: Handles input/output and connects model to view.

Request → Controller → Model → DB

View ←

2. What are the benefits of using a PHP framework like Laravel?

Explanation:

 Follows MVC

 Security (CSRF, SQL injection)

 Eloquent ORM

 Artisan CLI

 Routing system

 Blade templating

3. How do you create a Laravel project?

composer create-project laravel/laravel myApp

Explanation:
Installs Laravel in a folder named myApp.

4. How do you define a route in Laravel?

// routes/web.php

Route::get('/hello', function () {

return 'Hello, Laravel!';

});
Explanation:
Defines a URL /hello returning a simple response.

5. How do you create a controller in Laravel?

php artisan make:controller StudentController

Explanation:
Generates StudentController.php in app/Http/Controllers.

🔹 Laravel Features & Code Practice (Q6–Q15)

6. How do you return a view with data?

// Controller

return view('welcome', ['name' => 'Alice']);

blade

CopyEdit

<!-- welcome.blade.php -->

Hello, {{ $name }}

Explanation:
Passes variable $name to the view.

7. How do you use Blade syntax in Laravel?

@foreach($students as $student)

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

@endforeach

Explanation:
Blade templating engine uses {{ }} and directives like @foreach.

8. How to create a model and migration in Laravel?

php artisan make:model Student -m

Explanation:
Creates a Student.php model and migration file for the table.

9. How to define a database schema?


// In migration file

Schema::create('students', function (Blueprint $table) {

$table->id();

$table->string('name');

$table->timestamps();

});

Explanation:
Defines a database table with columns.

10. How to insert data using Eloquent?

$student = new Student;

$student->name = 'John';

$student->save();

Explanation:
Saves a new student record to the DB.

11. How to retrieve all records using Eloquent?

$students = Student::all();

Explanation:
Returns all rows from students table.

12. How to validate a form in Laravel?

$request->validate([

'name' => 'required|min:3'

]);

Explanation:
Validates that name is present and has at least 3 characters.

13. How to update a record in Laravel?

$student = Student::find(1);

$student->name = 'Updated';

$student->save();
Explanation:
Finds student by ID and updates the name.

14. How to delete a record in Laravel?

Student::destroy(1);

Explanation:
Deletes the student with ID 1 from the DB.

15. How to create a resource controller?

php artisan make:controller StudentController --resource

Explanation:
Creates methods like index, store, update, destroy for CRUD.

🔹 Mini Project (Student Management) (Q16–Q18)

16. How to create a student form using Blade?

<form action="/students" method="POST">

@csrf

<input type="text" name="name">

<button type="submit">Save</button>

</form>

Explanation:
Sends POST request with CSRF token for storing data.

17. How to use route resource for RESTful CRUD?

Route::resource('students', StudentController::class);

Explanation:
Automatically sets up 7 RESTful routes for the controller.

18. What are the 7 RESTful methods in a Laravel controller?

 index() – Show all

 create() – Show form

 store() – Save new


 show() – Show single

 edit() – Show edit form

 update() – Update

 destroy() – Delete

Explanation:
Each handles a typical part of CRUD flow.

🔹 Semantic Web and RDF (Q19–Q22)

19. What is Semantic Web?

Explanation:
The Semantic Web enhances web data with meaning for machines using standards like RDF, OWL,
and SPARQL.

20. What is RDF in Semantic Web?

Explanation:
RDF (Resource Description Framework) describes data in triples:
Subject → Predicate → Object

21. What is RAP (RDF API for PHP)?

Explanation:
RAP is a PHP library to manipulate RDF data, supporting:

 RDF parsing/serialization

 RDF storage

 SPARQL queries

22. How to create an RDF triple using RAP?

include("rap/RDFAPI.php");

$model = ModelFactory::getDefaultModel();

$resource = $model->createResource("http://example.com/student/1");

$resource->addProperty("http://xmlns.com/foaf/0.1/name", "Alice");

$model->writeAsHtml();
Explanation:
Creates a student RDF record and displays it as HTML using RAP.

🔹 Web Hosting (Q23–Q25)

23. How to host a Laravel project on cPanel?

Steps:

 Upload Laravel project via File Manager or FTP

 Point domain to /public folder

 Set permissions for storage and bootstrap/cache

 Update .env with production DB config

24. How to connect Laravel with MySQL on server?

DB_CONNECTION=mysql

DB_HOST=localhost

DB_PORT=3306

DB_DATABASE=your_db

DB_USERNAME=your_user

DB_PASSWORD=your_pass

Explanation:
Set proper credentials in .env file to connect Laravel with MySQL.

25. How to import a database on hosting (phpMyAdmin)?

Steps:

1. Open cPanel → phpMyAdmin

2. Create a new database

3. Click "Import" → Upload .sql file

4. Update .env with database info

Explanation:
This imports your project’s DB so it works live on the server.

You might also like