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

Blogging Application #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
51 changes: 0 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +0,0 @@
# Back-end developer exercise

© 2018 Renderbit Technologies LLP.

## Prerequisites

You should be familiar with PHP 7, Laravel 5, Git and GitHub.

## Getting Started

This tutorial assumes you have a PHP 7 development environment set up on your machine, with the following components at minimum:

1. PHP 7.1 or better
2. Choice of server (Apache/Nginx)
3. Choice of Database (MySQL/MariaDB/PostgreSQL/SQLite)
4. Choice of IDE/Editor

Fork this repository, and clone your fork locally. All submissions have to be made as a pull request against this repository.

## Requirements

You have to design a blogging application.

Any user can sign up and create a blog of their own. When signing up, you have to record the user's full name, unique email address, password (8 characters minimum with 1 special character required) and choice of unique username.

The homepage of the blog can be viewed by anyone without login. The homepage shall show a list of all blog posts by all users, with most recent posts on top. The list of blog posts shall be paginated, with 8 posts per page. On clicking a post, a user can view the entire post content.

Every user shall have his/her blog home page at `<sitename>/<username>`. This page shall show a list of all posts by the particular user, with most recent posts on top. This list of blog posts shall also be paginated, with 8 posts per page. On clicking a post, a user can view the entire post content.

A blog post has the URL `<sitename>/<username>/<post_unique_slug_from_title>`. A blog post has a post title and post content. Anyone can view a blog post without login. However, you need to login to comment on a blog post. Any user can comment on any blog post. However, a user can only delete comments that he has made on other users' blog posts. The author of the blog post can delete any comment on the blog post made by any user. The comments are shown below the blog post content, with most recent comments on top. A form to add a new comment is shown above the comments thread.

Every user can access the admin panel at `<sitename>/admin`. A user has to login to access the admin panel. The admin panel should show a list of all posts, with an option to edit and delete each post. The admin panel should also have an option to create a new post.

### UI

You are free to use any UI framework or library of your choice. We recommend [Bootstrap](https://getbootstrap.com) as a good place to get started.

Note that you are not required to build a mobile responsive website, although if you build one, we will be assigning extra credits for that.

### Libraries & Frameworks

You are free to use any libraries, frameworks & tools which you think will be useful to build this application. No credits are deducted for use of libraries.

### Extra Credits

- Implement a social login feature which allows users to login and sign up via their Google+/Facebook/Twitter/Github accounts.
- Allow photos to be inserted into blog posts.
- Allow WYSIWYG editing of blog posts with rich formatting support.
- Implement a CAPTCHA for adding comments.
- Implement two-factor authentication for login using SMS for one-time passwords.
- Surprise us. :smiley:
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected function validator(array $data)
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'username' => ['required', 'string', 'max:255'],
]);
}

Expand All @@ -67,6 +68,7 @@ protected function create(array $data)
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'username' => $data['username'],
]);
}
}
37 changes: 37 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('home');
}
public function update(Request $req){
$data = User::find($req->id);
$data->name = $req->input('name');
$data->email = $req->input('email');
$data->username = $req->input('username');
$data->save();
return redirect('profile');
}
}
65 changes: 65 additions & 0 deletions app/Http/Controllers/blogcontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Session;
use Auth;
use Illuminate\Support\Facades\Storage;
use App\blog;
use App\comment;
use Illuminate\Support\Facades\DB;

class blogcontroller extends Controller
{
function add(Request $req){

$data = new blog;
if($req->hasFile('image')){
$fileName = $req->image->getClientOriginalName();
if($req->image->move(public_path('images'),$fileName)){
$data->image=$fileName;
$data->name = Auth::user()->name;
$data->title=$req->input('title');
$data->email=Auth::user()->email;
$data->content=$req->input('content');
$data->save();
return "<script>alert('Your Blog is sent for review');document.location='homepage'</script>";
}
else{
// here put code that will tell user that some error in uloading file is present and no need to carry on further tasks, exxit here
return "<script>alert('Your Blog was Not Uploaded. PLease try again!');document.location='homepage'</script>";
}
}else{
echo "not found.";
}
}
function select(){
$data=blog::all();
return view('dashboard.dash_blog',["data"=>$data]);
}
function home_select(){
$data = blog::orderBy('created_at', 'DESC')->paginate(8);
for($j = 0 ; $j<sizeof($data) ; $j++){
$comments = [];
$commentt = blog::find($data[$j]['id'])->comments;

for($i=0;$i<sizeof($commentt);$i++){
array_push($comments, $commentt[$i]);
}
$data[$j]['comments'] = $comments;
}
return view('/homepage',["data"=>$data]);
}
function update($id){
$data=blog::find($id);
$data->status='Accepted';
$data->save();
return redirect('blog');
}
function delete($id){
blog::find($id)->delete();

return redirect('/blog');
}
}
61 changes: 61 additions & 0 deletions app/Http/Controllers/commentcontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Http\Controllers;
use App\User;
use App\comment;
use App\blog;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Auth;

class commentcontroller extends Controller
{
function add(Request $req){
$userid = Auth::user()->id; //userid
$data = new comment;
$data->comment = $req->comment;
$data->user_id = $userid;
$data->blog_id = $req->id;
$data->save();
return redirect('/homepage');
}
function select(){
if(Auth::user()->role == "admin")
{
$data = comment::all();
$commment = [];
for($i = 0; $i < sizeof($data); $i++){
array_push($commment,$data[$i]);
$name = User::find($data[$i]['user_id']);
$commment[$i]['name'] = $name->username;
}
return view('dashboard.dash_comments',["data"=>$commment]);
}
else{
$data = comment::all();
$commment = [];
for($i = 0; $i < sizeof($data); $i++){
array_push($commment,$data[$i]);
$name = User::find($data[$i]['user_id']);
$commment[$i]['name'] = $name->username;
}
$username = Auth::user()->name;
$users = DB::table('blogs')->select('id')->where('name', '=', $username)->get();

$newcomment = [];

for($i = 0 ; $i<sizeof($users) ; $i++){
for($j=0;$j<sizeof($commment);$j++){
if($users[$i]->id == $commment[$j]['blog_id']){
array_push($newcomment , $commment[$j]);
}
}
}
}
return view('dashboard.dash_comments',["data"=>$newcomment]);
}
function delete($id){
comment::find($id)->delete();
return redirect('/comments');
}
}
30 changes: 30 additions & 0 deletions app/Http/Controllers/contactcontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\contact;
use App\User;
use Auth;

class contactcontroller extends Controller
{
public function insert(Request $req){
$data = new contact;
$data->name=Auth::user()->name;
$data->email=Auth::user()->email;
$data->subject=$req->input('subject');
$data->message=$req->input('message');
$data->save();
return "<script>alert('Your message has been sent to the admin!');document.location='home'</script>";
}
function select(){
$data=contact::all();
return view('dashboard.dash_contactus',["data"=>$data]);
}
function delete($id){
contact::find($id)->delete();
\Session::flash('status','Message deleted successfully!');
return redirect('home');
}
}
2 changes: 1 addition & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'name', 'email', 'password', 'username' ,
];

/**
Expand Down
13 changes: 13 additions & 0 deletions app/blog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class blog extends Model
{
public function comments()
{
return $this->hasMany('App\comment');
}
}
10 changes: 10 additions & 0 deletions app/comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class comment extends Model
{
//
}
10 changes: 10 additions & 0 deletions app/contact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class contact extends Model
{
//
}
Loading