Skip to content

Commit

Permalink
second Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Adnank999 committed Aug 17, 2023
1 parent d97535b commit d2768e4
Show file tree
Hide file tree
Showing 1,831 changed files with 494,601 additions and 34 deletions.
10 changes: 10 additions & 0 deletions app/Enums/PollStatus.php
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';
}
9 changes: 8 additions & 1 deletion app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function store(Request $request): RedirectResponse
{
$request->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:'.User::class],
'email' => ['required', 'string', 'email', 'max:255', 'unique:' . User::class],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);

Expand All @@ -42,10 +42,17 @@ public function store(Request $request): RedirectResponse
'password' => Hash::make($request->password),
]);

$user->addRole($request->role_id);
event(new Registered($user));

Auth::login($user);




return redirect(RouteServiceProvider::HOME);


// return redirect(RouteServiceProvider::USERVEIEW);
}
}
58 changes: 58 additions & 0 deletions app/Http/Controllers/BackendController.php
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');


}
}
114 changes: 114 additions & 0 deletions app/Http/Controllers/BlogController.php
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);
}
}
38 changes: 38 additions & 0 deletions app/Http/Controllers/DashboardController.php
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');














}


}
}
27 changes: 27 additions & 0 deletions app/Http/Controllers/FileController.php
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]);

}
}
105 changes: 105 additions & 0 deletions app/Http/Controllers/PollController.php
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();
}
}
Loading

0 comments on commit d2768e4

Please sign in to comment.