Skip to content

Commit

Permalink
Split Tag Management into Events,Locations & Scheme_Plans for better …
Browse files Browse the repository at this point in the history
…eloquent queries
  • Loading branch information
bhaviljain68 committed Oct 13, 2023
1 parent 30d8a5a commit 44ca497
Show file tree
Hide file tree
Showing 30 changed files with 3,997 additions and 297 deletions.
71 changes: 71 additions & 0 deletions app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace App\Http\Controllers;

use App\Models\Event;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class EventController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index():Response
{
$tags = Event::orderBy("event");
return Inertia::render("Tags/Index", [
"tags" => $tags,
"type" => "event"
]);
}

/**
* Show the form for creating a new resource.
*/
public function create()
{

}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}
71 changes: 71 additions & 0 deletions app/Http/Controllers/LocationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace App\Http\Controllers;

use App\Models\Location;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class LocationController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(): Response
{
$tags = Location::orderBy("location");
return Inertia::render("Tags/Index", [
"tags" => $tags,
"type" => "event"
]);
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}
28 changes: 17 additions & 11 deletions app/Http/Controllers/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
namespace App\Http\Controllers;

use App\Http\Requests\PostRequest;
use App\Models\Event;
use App\Models\Location;
use App\Models\Post;
use App\Models\Tag;
use App\Models\SchemePlan;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\URL;
use Inertia\Inertia;
use Illuminate\Support\Str;
use Inertia\Response;

class PostsController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
public function index(): Response
{
$posts = Post::orderBy("created_at", "desc")->with("user:id,name,avatar_thumb")->with("tags")->get();
$posts = Post::orderBy("created_at", "desc")->with("user:id,name,avatar_thumb")->with("events","locations","schemePlans")->get();
return Inertia::render("Posts/Index", [
"posts" => $posts
]);
Expand All @@ -30,22 +34,24 @@ public function index()
/**
* Show the form for creating a new resource.
*/
public function create()
public function create(): Response
{
return Inertia::render("Posts/CreateEdit", [
"mode" => "create",
"tags" => Tag::all()
"events" => Event::all(),
"locations" => Location::all(),
"scheme_plans" => SchemePlan::all(),
]);
}

/**
* Store a newly created resource in storage.
*/
public function store(PostRequest $request)
public function store(PostRequest $request): \Illuminate\Http\RedirectResponse
{

try
{

$baseUrl = URL::to('/') . "/storage/";
$path = "blog-hero-images/";
$savedPath = encodeAndSaveImage($request->hero, $path, "webp");
Expand All @@ -64,10 +70,10 @@ public function store(PostRequest $request)
$tagsPosts = [];
foreach ($request->tags as $tag)
{
array_push($tagsPosts, [
$tagsPosts[] = [
"tag_id" => $tag,
"post_id" => $post->id,
]);
];
}
DB::table("tags_posts")->insert($tagsPosts);
DB::commit();
Expand Down Expand Up @@ -108,7 +114,7 @@ public function edit(Post $post)
/**
* Update the specified resource in storage.
*/
public function update(PostRequest $request, string $id)
public function update(PostRequest $request, string $id): RedirectResponse
{
try
{
Expand Down Expand Up @@ -178,7 +184,7 @@ public function destroy(Post $post)
return Redirect::route('posts.index');
}

public function saveImage(Request $request)
public function saveImage(Request $request): \Illuminate\Http\JsonResponse
{
try
{
Expand Down
72 changes: 72 additions & 0 deletions app/Http/Controllers/SchemePlanController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace App\Http\Controllers;

use App\Models\Location;
use App\Models\SchemePlan;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class SchemePlanController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(): Response
{
$tags = SchemePlan::orderBy("scheme_plan");
return Inertia::render("Tags/Index", [
"tags" => $tags,
"type" => "event"
]);
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}
Loading

0 comments on commit 44ca497

Please sign in to comment.