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

Blog #3

Open
wants to merge 18 commits into
base: main
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
33 changes: 33 additions & 0 deletions blog/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
5 changes: 5 additions & 0 deletions blog/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
CHANGELOG.md export-ignore
12 changes: 12 additions & 0 deletions blog/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
/.idea
/.vagrant
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.env
16 changes: 16 additions & 0 deletions blog/app/Author.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Author extends Model
{
protected $table = 'author_table';
protected $fillable = ['names','email', 'password'];

public function publishedArticles()
{
return $this->hasMany(PublishArticle::class, 'author_id');
}
}
17 changes: 17 additions & 0 deletions blog/app/Categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Categories extends Model
{
protected $table = 'categories';
protected $fillable = ['category_name', 'author_id'];

public function author()
{
return $this->belongsTo(Author::class, 'author_id');
}
}

40 changes: 40 additions & 0 deletions blog/app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
}

/**
* Register the Closure based commands for the application.
*
* @return void
*/
protected function commands()
{
require base_path('routes/console.php');
}
}
65 changes: 65 additions & 0 deletions blog/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
\Illuminate\Auth\AuthenticationException::class,
\Illuminate\Auth\Access\AuthorizationException::class,
\Symfony\Component\HttpKernel\Exception\HttpException::class,
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Session\TokenMismatchException::class,
\Illuminate\Validation\ValidationException::class,
];

/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}

/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}

return redirect()->guest(route('login'));
}
}
130 changes: 130 additions & 0 deletions blog/app/Http/Controllers/AuthorLoginController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
namespace App\Http\Controllers;

use App\Author;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\PublishArticle;
use App\Categories;
use DB;

class AuthorLoginController extends Controller
{
public function loginAuthor(Request $request)
{

$email = $request->input('email');
$password = $request->input('password');

$user = Author::where('email', $email)->first();

if (!$user) {
return redirect()->back()->with('message', 'Login failed: Email not found');
}

if ($user->password == $password) {
session(['user_id' => $user->id]);
return view('publish_article');

} else {
return redirect()->back()->with('message', 'Login failed: Incorrect password');
}
}

public function AuthorArticles() {
$user_id = session('user_id');
$author = Author::find($user_id);

if ($author) {

$author_articles = $author->publishedArticles;

return view('published_articles', ['author_articles' => $author_articles]);
} else {

return redirect()->back()->with('message', 'Author not found');
}
}


public function displayEntireArticle($id)

{
$article = PublishArticle::find($id);
return view('author_articles', ['article' => $article]);
}

public function editArticle($id)
{
$articles = PublishArticle::find($id);
return view('author_articles', ['article' => $article]);
}

public function deleteArticle($id){
DB::table('publish_articles')->where('id', $id)->delete();
return redirect()->back()->with('success', 'Article deleted Successfully');

}


public function updateArticle(Request $request, $id)
{
$this->validate($request,[
'author_name'=>'required',
'article_title' => 'required',
'article_body' => 'required'
]);
$author_name = $request->input('author_name');
$article_title = $request->input('article_title');
$article_body = $request->input('article_body');
DB::update('UPDATE publish_articles SET author_name = ?, article_title = ?, article_body = ? WHERE id = ?', [$author_name, $article_title, $article_body, $id]);
return redirect()->back()->with('success', 'Article Updated Successfully');
}


public function AddCategory(Request $request)
{
$category_info = new Categories;
$user_id = session('user_id');
$category_info->author_id = $user_id;
$category_info->category_name = $request->input('category_name');

$existingCategory = Categories::where('category_name', $category_info->category_name)->first();

if ($existingCategory) {
return redirect('add_categories')->with('message', 'Failed: The Category is already available');
}

$category_info->save();
return redirect('add_categories')->with('success', 'Category Added Successfully');
}

public function displayCategories() {
$user_id = session('user_id');
$categories =Categories::where('author_id', $user_id)->paginate(5);
return view('publish_article', ['categories' => $categories]);
}

public function editCategories($id){
$articles = Categories::find($id);
return view('manage_categories', ['categories' => $categories]);
}


public function updateCategories(Request $request, $id){
$this->validate($request,[
'category_name'=>'required',

]);
$category_name = $request->input('category_name');
DB::update('UPDATE categories SET category_name = ? WHERE id = ?', [$category_name, $id]);
return redirect()->back()->with('success', 'Category Updated Successfully');
}


public function deleteCategories($id){
DB::table('categories')->where('id', $id)->delete();
return redirect()->back()->with('success', 'Category deleted Successfully');
}
}

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

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
28 changes: 28 additions & 0 deletions blog/app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

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');
}
}
Loading