Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed typo in README.md #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The DataFrame php Framework is a mini php framework to help in daily php problem

Basic features found are:-
- Basic Routing
- MVC archtecture
- MVC architecture
- Use of namespaces
- ORM support similar to that of the famous Laravel's Eloquent
- A Basic php Template engine (purely php)
Expand Down Expand Up @@ -119,3 +119,66 @@ class HomeController extends Controller{
}
}
```

- how to handle basic relations i.e (one-to-one, one-to-many, many-to-many, and polymorphic)
- This simple framework will help you as well with this hard task

```php

<?php
namespance App;
Use DataFrame\Models\Elegant;
class User extends Elegant{
protected static $table_name = "users";
public function userType(){
return $this->hasOne("Type"); // you can change the relational foreign key but assumes it is user_id in types;
}

public function photos(){
return $this->mergeableMany("Photograph", "imageable"); // polymophic
}

public function products(){
return $this->hasMany("Product"); // one to many
}
public function groups(){
return $this->belongsToMany("Group"); // many to many ,assumes pivot table to be group_user
}
}

class Product extends Elegant{
public function user(){
return $this->belongsTo("User"); // reverse one to one
}
public function photos(){
return $this->mergeableMany("Photograph", "imageable"); // polymophic
}
}

class Group extends Elegant{
public function users(){
return $this->belongsToMany("User"); // many to many ,assumes pivot table to be group_user
}
}

class Photograph extends Elegant{
public function imageable(){
return $this->mergeable();
}
}

```
- How to use these models
```php
<?php

$user = User::find(1); // finds user whose primary key is 1
$userPhotos = $user->photos; // returns an array of photos where imageable_id = 1 & imageable_type = 'user'

// you can also trim result sets function using the query builder that comes with the Elegant Mode class

$userPhotos = $user->photos()->where("created_at", "2000-12-20")->get;

$userProducts = $user->products;

```