1. Go to this page and download the library: Download drahil/stutter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// User model
public function profile()
{
return $this->hasOne(Profile::class);
}
public function posts()
{
return $this->hasMany(Post::class);
}
// Profile model
public function user()
{
return $this->belongsTo(User::class);
}
// Post model
public function user()
{
return $this->belongsTo(User::class);
}
public function tags()
{
return $this->belongsToMany(Tag::class, 'post_tag', 'post_id', 'tag_id');
}
// Tag model
public function posts()
{
return $this->belongsToMany(Post::class, 'post_tag', 'tag_id', 'post_id');
}
// Get a user's profile
$profile = User::find(1)->profile()->get();
// Get a profile's user
$user = Profile::find(1)->user()->get();
// Create a profile for a user
$profile = User::find(1)->profile()->create([
'bio' => 'New bio for user'
]);
// Get a user's posts
$posts = User::find(1)->posts()->get();
// Get a post's user
$user = Post::find(1)->user()->get();
// Create a profile for a user
$profile = User::find(1)->profile()->create([
'bio' => 'New bio for user'
]);
// Get a post's tags
$tags = Post::find(1)->tags()->get();
// Get a tag's posts
$posts = Tag::find(1)->posts()->get();
// Attach tags to a post
Post::find(1)->tags()->attach([1, 2, 3]);
// Detach tags from a post
Post::find(1)->tags()->detach([2, 3]);