PHP Frameworks
PHP Frameworks
Explanation:
MVC (Model-View-Controller) is a design pattern that separates logic:
View ←
Explanation:
Follows MVC
Eloquent ORM
Artisan CLI
Routing system
Blade templating
Explanation:
Installs Laravel in a folder named myApp.
// routes/web.php
Route::get('/hello', function () {
});
Explanation:
Defines a URL /hello returning a simple response.
Explanation:
Generates StudentController.php in app/Http/Controllers.
// Controller
blade
CopyEdit
Hello, {{ $name }}
Explanation:
Passes variable $name to the view.
@foreach($students as $student)
@endforeach
Explanation:
Blade templating engine uses {{ }} and directives like @foreach.
Explanation:
Creates a Student.php model and migration file for the table.
$table->id();
$table->string('name');
$table->timestamps();
});
Explanation:
Defines a database table with columns.
$student->name = 'John';
$student->save();
Explanation:
Saves a new student record to the DB.
$students = Student::all();
Explanation:
Returns all rows from students table.
$request->validate([
]);
Explanation:
Validates that name is present and has at least 3 characters.
$student = Student::find(1);
$student->name = 'Updated';
$student->save();
Explanation:
Finds student by ID and updates the name.
Student::destroy(1);
Explanation:
Deletes the student with ID 1 from the DB.
Explanation:
Creates methods like index, store, update, destroy for CRUD.
@csrf
<button type="submit">Save</button>
</form>
Explanation:
Sends POST request with CSRF token for storing data.
Route::resource('students', StudentController::class);
Explanation:
Automatically sets up 7 RESTful routes for the controller.
update() – Update
destroy() – Delete
Explanation:
Each handles a typical part of CRUD flow.
Explanation:
The Semantic Web enhances web data with meaning for machines using standards like RDF, OWL,
and SPARQL.
Explanation:
RDF (Resource Description Framework) describes data in triples:
Subject → Predicate → Object
Explanation:
RAP is a PHP library to manipulate RDF data, supporting:
RDF parsing/serialization
RDF storage
SPARQL queries
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.
Steps:
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.
Steps:
Explanation:
This imports your project’s DB so it works live on the server.