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

Laravel v7.0 #3

Open
wants to merge 70 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
64c8e6f
Design answers table schema and rename answers column to answers_coun…
programmerShinobi Aug 31, 2022
d4acc41
Generate fake answers
programmerShinobi Sep 2, 2022
5fda0a5
display answers for question
programmerShinobi Sep 3, 2022
3287ce8
Add vote controll to question and answer item
programmerShinobi Sep 12, 2022
34cd68e
Display answers for question
programmerShinobi Sep 22, 2022
b5fcd6e
Implement update answer
programmerShinobi Sep 22, 2022
0215f62
Implement delete functionality for answer
programmerShinobi Sep 22, 2022
71a976b
Update best_answer_id on questions table when an answer removed using…
programmerShinobi Sep 22, 2022
0999341
Update best_answer_id on questions table when answer removed in datab…
programmerShinobi Sep 22, 2022
d9db1e0
Implement accept the answer as best answer
programmerShinobi Sep 22, 2022
1165563
Implement many to many relationship and make the favorite button works
programmerShinobi Sep 22, 2022
3897552
Implement many to many polymorphic relationship and make the vote que…
programmerShinobi Sep 23, 2022
fd20f68
Make the vote answer working
programmerShinobi Sep 23, 2022
8010e21
Implement DRY principle Answer and Question model
programmerShinobi Sep 24, 2022
de5e5c2
Implement DRY principle on the application views
programmerShinobi Sep 24, 2022
eb94b13
Securing the application from xss attack
programmerShinobi Sep 24, 2022
6c5f1a2
- Display all questions in root route (front page)
programmerShinobi Sep 24, 2022
83bd689
Tidy up views (FIXED ALL)
programmerShinobi Sep 24, 2022
118981f
Create a basic Vue.js component
programmerShinobi Oct 4, 2022
153053b
fix unused files
programmerShinobi Oct 4, 2022
2c8c5d9
Create vue answer component
programmerShinobi Oct 4, 2022
fedfb4b
Ajaxifly the delete button
programmerShinobi Oct 5, 2022
0984998
Beautiy the flash message and confirm dialog
programmerShinobi Oct 5, 2022
29c7766
Rewrite the favorite button into Vue.js component
programmerShinobi Oct 5, 2022
1d40577
Create accept answer component
programmerShinobi Oct 6, 2022
2d0d122
Rewrite the authorization policy into javascript code
programmerShinobi Oct 6, 2022
ac28939
Rewrite the vote control into Vue.js component
programmerShinobi Oct 7, 2022
5507fc5
Create Answers component and implement vue list rendering
programmerShinobi Oct 7, 2022
893e31b
Implement load more answers feature
programmerShinobi Oct 7, 2022
15fe362
Implement Vue.js custom events on the answer deletion
programmerShinobi Oct 7, 2022
8a44675
Fix issue on accept component by implementing event bus
programmerShinobi Oct 7, 2022
821c02a
Create new answer component
programmerShinobi Oct 7, 2022
ffce763
Create and Question Page component
programmerShinobi Oct 8, 2022
202e1cf
Utilizing Vue.js mixins
programmerShinobi Oct 8, 2022
ce44525
Create markdown editor component
programmerShinobi Oct 8, 2022
0372852
make the preview the functional
programmerShinobi Oct 8, 2022
830bad7
Implement autosize textarea
programmerShinobi Oct 8, 2022
6630cda
Integrate syntax highlight
programmerShinobi Oct 8, 2022
412cf73
Fix syntax highlight issue on the first load
programmerShinobi Oct 8, 2022
67a9fc5
Fix syntax highlight after editing
programmerShinobi Oct 8, 2022
43ad3e3
Create syntax highlight mixins
programmerShinobi Oct 8, 2022
aea3dfa
Add markdown editor in answer component
programmerShinobi Oct 9, 2022
9666637
Integrate Markdown editor in NewAnswer component
programmerShinobi Oct 9, 2022
3f1cc24
Fix syntax highlight issue when new answer added
programmerShinobi Oct 9, 2022
82b8c29
Fix syntax in Answers Component
programmerShinobi Oct 9, 2022
57a9051
Install & Configure Laravel for API Authentication
programmerShinobi Oct 17, 2022
a655f1b
Create api endpoint for displaying all questions
programmerShinobi Oct 17, 2022
193a6b1
Create an endpoint to create question
programmerShinobi Oct 17, 2022
bd1069d
Create update & delete question endpoints
programmerShinobi Oct 17, 2022
e748016
Create api endpoint to show question details
programmerShinobi Oct 17, 2022
3c7ed7e
Create some endpoints for answer resource
programmerShinobi Oct 17, 2022
0eb688f
Create api endpoints for vote question and answer
programmerShinobi Oct 18, 2022
117e4e8
Create api endpoints for favoriting the question & accepting answer
programmerShinobi Oct 18, 2022
e79fcc6
create additional api endpoint to display current user's posts
programmerShinobi Oct 18, 2022
7048fe8
Create Api endpoints for Authentication
programmerShinobi Oct 18, 2022
4fa574d
Working with vue routerzzzz'
programmerShinobi Nov 1, 2022
061687f
Consume all questions endpoint on QuestionsPage component
programmerShinobi Nov 2, 2022
603e265
Create Pagination component
programmerShinobi Nov 5, 2022
e7aac92
Add Create Question Page component
programmerShinobi Nov 6, 2022
44fb9ba
Create Edit Question component
programmerShinobi Nov 7, 2022
43d5924
Make the delete button in QuestionExcerpt functional
programmerShinobi Nov 7, 2022
89175e3
Fix some issues on QuestionPage component
programmerShinobi Nov 9, 2022
08c66f3
Display current user's posts in MyPostsPage component
programmerShinobi Nov 9, 2022
db88761
Add transition effect & AJAX spinner
programmerShinobi Nov 10, 2022
29fe293
Bugfix pagination, delete question & auth redirection issue
programmerShinobi Nov 10, 2022
76a5e0c
Upgrade to Laravel 5.7
programmerShinobi Nov 17, 2022
c31e24c
Upgrade to laravel 5.8
programmerShinobi Nov 17, 2022
2189950
Update to laravel version 6.0
programmerShinobi Nov 18, 2022
d8be1ea
Add Procfile for Heroku
programmerShinobi Nov 19, 2022
68d4afb
Update to laravel version 7.*
programmerShinobi Nov 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
542 changes: 542 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions app/Answer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
namespace App;

use Parsedown;
use Illuminate\Database\Eloquent\Model;

class Answer extends Model
{
use VotableTrait;

protected $fillable = ['body', 'user_id'];

protected $appends = ['created_date', 'body_html', 'is_best'];

public function question()
{
return $this->belongsTo(Question::class);
}

public function user()
{
return $this->belongsTo(User::class);
}

public function getBodyHtmlAttribute()
{
return clean(\Parsedown::instance()->text($this->body));
}

public static function boot()
{
parent::boot();

static::created(function ($answer) {
$answer->question->increment('answers_count');
});

static::deleted(function ($answer) {
$answer->question->decrement('answers_count');
});
}

public function getCreatedDateAttribute()
{
return $this->created_at->diffForHumans();
}

public function getStatusAttribute()
{
return $this->isBest() ? 'vote-accepted' : '';
}

public function getIsBestAttribute()
{
return $this->isBest();
}

public function isBest()
{
return $this->id === $this->question->best_answer_id;
}
}
3 changes: 1 addition & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
// $schedule->command('inspire')->hourly();
}

/**
Expand Down
18 changes: 10 additions & 8 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
Expand All @@ -29,12 +29,12 @@ class Handler extends ExceptionHandler
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @param \Throwable $exception
* @return void
*
* @throws \Throwable
*/
public function report(Exception $exception)
public function report(Throwable $exception)
{
parent::report($exception);
}
Expand All @@ -43,10 +43,12 @@ public function report(Exception $exception)
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
* @param \Throwable $exception
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Throwable
*/
public function render($request, Exception $exception)
public function render($request, Throwable $exception)
{
return parent::render($request, $exception);
}
Expand Down
25 changes: 25 additions & 0 deletions app/Http/Controllers/AcceptAnswerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Controllers;

use App\Answer;
use Illuminate\Http\Request;

class AcceptAnswerController extends Controller
{
public function __invoke(Answer $answer)
{
$this->authorize('accept', $answer);

$answer->question->acceptBestAnswer($answer);

if (request()->expectsJson()) {
return response()->json([
'message' => "You have accepted this answer as best answer"
]);
}

return back();
}
}

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

namespace App\Http\Controllers;

use App\Answer;
use App\Question;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class AnswersController extends Controller
{
public function __construct()
{
$this->middleware('auth')->except('index');
}

public function index(Question $question)
{
return $question->answers()->with('user')->simplePaginate(3);
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Question $question, Request $request)
{
$answer = $question->answers()->create($request->validate([
'body' => 'required'
]) + ['user_id' => Auth::id()]);

if ($request->expectsJson()) {
return response()->json([
'message' => "Your answer has been submitted successfully",
'answer' => $answer->load('user')
]);
}

return back()->with('success', "Your answer has been submitted successfully");
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Answer $answer
* @return \Illuminate\Http\Response
*/
public function edit(Question $question, Answer $answer)
{
$this->authorize('update', $answer);

return view('answers.edit', compact('question', 'answer'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Answer $answer
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Question $question, Answer $answer)
{
$this->authorize('update', $answer);

$answer->update($request->validate([
'body' => 'required',
]));

if ($request->expectsJson()) {
return response()->json([
'message' => 'Your answer has been updated',
'body_html' => $answer->body_html
]);
}

return redirect()->route('questions.show', $question->slug)->with('success', 'Your answer has been updated');
}

/**
* Remove the specified resource from storage.
*
* @param \App\Answer $answer
* @return \Illuminate\Http\Response
*/
public function destroy(Question $question, Answer $answer)
{
$this->authorize('delete', $answer);

$answer->delete();

if (request()->expectsJson()) {
return response()->json([
'message' => "Your answer has been removed",
'answer' => $answer->load('user')
]);
}

return back()->with('success', "Your answer has been removed");
}
}
22 changes: 22 additions & 0 deletions app/Http/Controllers/Api/AcceptAnswerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers\Api;

use App\Answer;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class AcceptAnswerController extends Controller
{
public function __invoke(Answer $answer)
{
$this->authorize('accept', $answer);

$answer->question->acceptBestAnswer($answer);

return response()->json([
'message' => "You have accepted this answer as best answer"
]);
}
}

Loading