-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1,831 changed files
with
494,601 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
enum PollStatus : string { | ||
|
||
case PENDING = 'PENDING'; | ||
case STARTED = 'STARTED'; | ||
case FINISHED = 'FINISHED'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Blog; | ||
use Illuminate\Http\Request; | ||
|
||
class BackendController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$allblogs = Blog::all(); | ||
|
||
// return response()->json([ | ||
// 'results' => $allblogs | ||
// ], 200); | ||
|
||
return view('admin.allblogs',compact('allblogs')); | ||
} | ||
|
||
|
||
public function show($id) | ||
{ | ||
|
||
$blog = Blog::find($id); | ||
|
||
if (!$blog) { | ||
return response()->json([ | ||
'message' => 'user not found' | ||
], 404); | ||
} | ||
|
||
// return response()->json([ | ||
// 'blogs' => $blog | ||
// ], 200); | ||
|
||
return view('admin.individual', compact('blog')); | ||
} | ||
|
||
|
||
public function delete($id) | ||
{ | ||
|
||
$blogs = Blog::find($id); | ||
if (!$blogs) { | ||
return $blogs()->json([ | ||
'message' => 'User not found!' | ||
], 404); | ||
} | ||
|
||
$blogs->delete(); | ||
|
||
return redirect()->route('allblogs'); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\BlogStoreRequest; | ||
use App\Models\Blog; | ||
use App\Models\User; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class BlogController extends Controller | ||
{ | ||
|
||
|
||
|
||
|
||
public function index() | ||
{ | ||
// $allblogs = Blog::all(); | ||
$allblogs = Blog::with('users')->get(); | ||
|
||
return response()->json([ | ||
'results' => $allblogs | ||
], 200); | ||
|
||
// return view('admin.allblogs',compact('allblogs')); | ||
} | ||
|
||
public function show($id) | ||
{ | ||
|
||
$blog = Blog::find($id); | ||
|
||
if (!$blog) { | ||
return response()->json([ | ||
'message' => 'user not found' | ||
], 404); | ||
} | ||
|
||
return response()->json([ | ||
'blogs' => $blog | ||
], 200); | ||
|
||
// return view('admin.individual', compact('blog')); | ||
} | ||
|
||
public function store(BlogStoreRequest $request,$id ) | ||
{ | ||
|
||
|
||
|
||
|
||
$imagePath = $request->file('image')->store('public/upload'); | ||
$cleanedPath = str_replace('public/', '', $imagePath); | ||
$imageUrl = config('app.url') . '/storage/' . $cleanedPath; | ||
|
||
|
||
$user = User::find($id); | ||
|
||
if($user){ | ||
|
||
|
||
Blog::insert([ | ||
'user_id' => $user->id, | ||
'user_name' => $user->name, | ||
'title' => $request->title, | ||
'description' => $request->description, | ||
// 'image' => $request->file('image')->store('upload'), | ||
'image' => $imageUrl, | ||
'thumbnail' => $request->thumbnail, | ||
'meta_description' => $request->meta_description, | ||
'meta_title' => $request->meta_title, | ||
'meta_keywords' => $request->meta_keywords | ||
|
||
|
||
|
||
]); | ||
}else{ | ||
|
||
return response()->json([ | ||
'message' => 'No user found' | ||
], 200); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
// return redirect()->route('blogs'); | ||
// } catch (\Exception $e) { | ||
// return response()->json([], 500); | ||
// } | ||
} | ||
|
||
public function delete($id) | ||
{ | ||
|
||
$blogs = Blog::find($id); | ||
if (!$blogs) { | ||
return $blogs()->json([ | ||
'message' => 'User not found!' | ||
], 404); | ||
} | ||
|
||
$blogs->delete(); | ||
|
||
return response()->json([ | ||
'message' => 'blog succesfully deleted' | ||
], 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class DashboardController extends Controller | ||
{ | ||
public function index(){ | ||
if(Auth::user()->hasRole('superadmin')){ | ||
return view('super'); | ||
} | ||
elseif(Auth::user()->hasRole('admin')){ | ||
return view('admin.dashboard'); | ||
} | ||
elseif(Auth::user()->hasRole('user')){ | ||
return view('admin.userdashboard'); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Blog; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
class FileController extends Controller | ||
{ | ||
function upload(Request $req) | ||
{ | ||
// $path=$req->file('file')->store('public/upload'); | ||
// return ["result"=>"$path"]; | ||
|
||
// $path = Storage::putFile('image', $req->image); | ||
// return response()->json(['path' => $path]); | ||
} | ||
|
||
public function getImage(Request $req) | ||
{ | ||
$filePath = Blog::all('image'); | ||
return response()->json(['path' => $filePath]); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use App\Enums\PollStatus; | ||
use App\Http\Requests\CreatePollRequest; | ||
use App\Http\Requests\UpdatePollRequest; | ||
use App\Http\Requests\VoteRequest; | ||
use App\Models\Option; | ||
use App\Models\Poll; | ||
use App\Models\Vote; | ||
use App\Models\User; | ||
|
||
|
||
class PollController extends Controller | ||
{ | ||
public function store(CreatePollRequest $request) | ||
{ | ||
$poll = auth()->user()->polls()->create($request->safe()->except('options')); | ||
|
||
$poll->options()->createMany($request->options); | ||
|
||
return back(); | ||
} | ||
|
||
public function index() | ||
{ | ||
$polls = auth()->user()->polls()->select('title','status','id')->paginate(10); | ||
|
||
return view('polls.list', compact('poll')); | ||
} | ||
|
||
public function edit(Poll $poll) | ||
{ | ||
abort_if(auth()->user()->isNot($poll->user), 403); | ||
abort_if($poll->status != PollStatus::PENDING->value, 404); | ||
|
||
$poll = $poll->load('options'); | ||
return view('polls.update', compact('polls')); | ||
} | ||
|
||
public function update(UpdatePollRequest $request, Poll $poll) | ||
{ | ||
|
||
$data = $request->safe()->except('options'); | ||
|
||
$poll->update($data); | ||
|
||
$poll->options()->delete(); | ||
|
||
$poll->options()->createMany($request->options); | ||
|
||
return to_route('poll.index'); | ||
} | ||
|
||
public function delete(Poll $poll) | ||
{ | ||
if ($poll->status != PollStatus::PENDING->value) { | ||
abort(404,'No Pending poll'); | ||
} | ||
|
||
$poll->options()->delete(); | ||
|
||
$poll->delete(); | ||
|
||
return back(); | ||
} | ||
|
||
public function show(Poll $poll) | ||
{ | ||
$poll = $poll->load('options'); | ||
|
||
$selectedOption = $poll->votes()->where('user_id', auth()->id())->first()?->option_id; | ||
|
||
if ($poll->user->is(auth()->user())) { | ||
return view('polls.show', compact('poll' ,'selectedOption')); | ||
} | ||
|
||
abort_if($poll->status != PollStatus::STARTED->value, 404); | ||
|
||
|
||
return view('polls.show', compact('polls', 'selectedOption')); | ||
} | ||
|
||
public function vote(VoteRequest $request, Poll $poll) | ||
{ | ||
|
||
abort_if($poll->status != PollStatus::STARTED->value, 404); | ||
$selectedOption = $poll->votes()->where('user_id', auth()->id())->first()->option; | ||
|
||
$poll->votes()->updateOrCreate(['user_id'=>auth()->id()],['option_id'=>$request->option_id]); | ||
|
||
$newOption = Option::find($request->option_id); | ||
$newOption->increment('votes_count'); | ||
|
||
if ($selectedOption) { | ||
$selectedOption->decrement('votes_count'); | ||
} | ||
|
||
$selectedOption = $newOption; | ||
return back(); | ||
} | ||
} |
Oops, something went wrong.