Reddit clone built with Laravel 5
Demo: http://maghnatis.com
- Login/Register
- Subreddits
- Posts (link and text)
- Moderators
- Search
- Threaded Comments with inline editing
- Upvote/Downvote
- User Profiles
- Sorting
- git clone https://github.com/Halnex/laravel-reddit projectname
- composer install
- php artisan migrate
Open AuthServiceProvider.php and import the following classes.
use Illuminate\Auth\Access\Gate;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
Now add the following method to the class
public function boot(GateContract $gate)
{
parent::registerPolicies($gate);
$gate->define('update-post', function ($user, $post, $isModerator) {
if ($user->id === $post->subreddit->user->id) {
return true;
}
if ($user->id === $post->user_id) {
return true;
}
if ($isModerator) {
return true;
}
return false;
});
$gate->define('update-sub', function($user, $subreddit) {
if($user->id === $subreddit->user->id) {
return true;
}
return false;
});
$gate->define('update-comment', function($user, $comment, $isModerator) {
if($user->id === $comment->user_id) {
return true;
}
if ($isModerator) {
return true;
}
});
}