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

chance_controllers_for_inertia_and_add_item_model #11

Merged
Merged
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
85 changes: 66 additions & 19 deletions app/Http/Controllers/AttachmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,96 @@

namespace App\Http\Controllers;

use App\Models\Attachment;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreAttachmentRequest;
use App\Http\Requests\UpdateAttachmentRequest;
use App\Http\Resources\AttachmentResource;
use App\Models\Attachment;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Inertia\Inertia;


class AttachmentController extends Controller
{

public static function routeName()
{
public static function routeName(){
return Str::snake("Attachment");
}
public function __construct(Request $request)
public function __construct(Request $request)
{
parent::__construct($request);
}

/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
return AttachmentResource::collection(Attachment::search($request)->sort($request)->paginate((request('per_page') ?? request('itemsPerPage')) ?? 15));

return Inertia::render(Str::studly("Attachment").'/Index', [
"headers" => Attachment::headers(),
"items" => Attachment::search($request)->sort($request)->paginate($this->pagination),

]);
}
public function store(StoreAttachmentRequest $request)

/**
* Show the form for creating a new resource.
*/
public function create()
{
$attachment = Attachment::create($request->validated());
return Inertia::render(Str::studly("Attachment").'/Create', [
// 'options' => $regions
]);
}

return new AttachmentResource($attachment);
/**
* Store a newly created resource in storage.
*/
public function store(StoreAttachmentRequest $request)
{
$data = $request->validated();
Attachment::create($data);

return to_route($this->routeName() . '.index')->with('res', ['message' => __('Attachment Saved Seccessfully'), 'type' => 'success']);
}
public function show(Request $request, Attachment $attachment)

/**
* Display the specified resource.
*/
// public function show(Attachment $attachment)
// {
//
// }

/**
* Show the form for editing the specified resource.
*/
public function edit(Attachment $attachment)
{
return new AttachmentResource($attachment);
return Inertia::render(Str::studly("Attachment").'/Update', [
//'options' => $regions,
'attachment' => $attachment->toArray()
]);
}

/**
* Update the specified resource in storage.
*/
public function update(UpdateAttachmentRequest $request, Attachment $attachment)
{
$attachment->update($request->validated());

return new AttachmentResource($attachment);
$validated = $request->validated();

$attachment->update($validated);
return back()->with('res', ['message' => __('Attachment Updated Seccessfully'), 'type' => 'success']);
}
public function destroy(Request $request, Attachment $attachment)

/**
* Remove the specified resource from storage.
*/
public function destroy(Attachment $attachment)
{
$attachment->delete();

return new AttachmentResource($attachment);
return back()->with('res', ['message' => __('Attachment Deleted Seccessfully'), 'type' => 'success']);
}
}
110 changes: 52 additions & 58 deletions app/Http/Controllers/BeneficiaryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,96 @@

namespace App\Http\Controllers;

use App\Models\Beneficiary;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreBeneficiaryRequest;
use App\Http\Requests\UpdateBeneficiaryRequest;
use App\Http\Resources\BeneficiaryResource;
use App\Models\Beneficiary;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Inertia\Inertia;


class BeneficiaryController extends Controller
{

public static function routeName()
{
public static function routeName(){
return Str::snake("Beneficiary");
}

public function __construct(Request $request)
public function __construct(Request $request)
{
parent::__construct($request);
}

/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
return view("dashboard." . $this->routeName() . ".index", [
'headers' => $this->getModelInstance()::headers(),
]);
}

return Inertia::render(Str::studly("Beneficiary").'/Index', [
"headers" => Beneficiary::headers(),
"items" => Beneficiary::search($request)->sort($request)->paginate($this->pagination),

public function indexApi(Request $request)
{
return BeneficiaryResource::collection(Beneficiary::search($request)->sort($request)->paginate((request('per_page') ?? request('itemsPerPage')) ?? 15));
]);
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
return view("dashboard." . $this->routeName() . ".create", [
'data_to_send' => 'Hello, World!',
$this->routeName() => $this->getModelInstance()
return Inertia::render(Str::studly("Beneficiary").'/Create', [
// 'options' => $regions
]);
}

/**
* Store a newly created resource in storage.
*/
public function store(StoreBeneficiaryRequest $request)
{
// if (!$this->user->is_permitted_to('store', Beneficiary::class, $request))
// return response()->json(['message' => 'not_permitted'], 422);

// $validator = Validator::make($request->all(), Beneficiary::createRules($this->user));
// if ($validator->fails()) {
// return response()->json(['errors' => $validator->errors()], 422);
// }
$beneficiary = Beneficiary::create($request->validated());
// if ($request->translations) {
// foreach ($request->translations as $translation)
// $beneficiary->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save();
// }
return new BeneficiaryResource($beneficiary);
$data = $request->validated();
Beneficiary::create($data);

return to_route($this->routeName() . '.index')->with('res', ['message' => __('Beneficiary Saved Seccessfully'), 'type' => 'success']);
}

public function show(Request $request, Beneficiary $beneficiary)
{
return view("dashboard." . $this->routeName() . ".show", [
'data_to_send' => 'Hello, World!',
$this->routeName() => $beneficiary
]);
}
/**
* Display the specified resource.
*/
// public function show(Beneficiary $beneficiary)
// {
//
// }

/**
* Show the form for editing the specified resource.
*/
public function edit(Beneficiary $beneficiary)
{
return view("dashboard." . $this->routeName() . ".edit", [
'data_to_send' => 'Hello, World!',
$this->routeName() => $beneficiary
return Inertia::render(Str::studly("Beneficiary").'/Update', [
//'options' => $regions,
'beneficiary' => $beneficiary->toArray()
]);
}

/**
* Update the specified resource in storage.
*/
public function update(UpdateBeneficiaryRequest $request, Beneficiary $beneficiary)
{
// if (!$this->user->is_permitted_to('update', Beneficiary::class, $request))
// return response()->json(['message' => 'not_permitted'], 422);
// $validator = Validator::make($request->all(), Beneficiary::updateRules($this->user));
// if ($validator->fails()) {
// return response()->json(['errors' => $validator->errors()], 422);
// }
$beneficiary->update($request->validated());
// if ($request->translations) {
// foreach ($request->translations as $translation)
// $beneficiary->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save();
// }
return new BeneficiaryResource($beneficiary);
$validated = $request->validated();

$beneficiary->update($validated);
return back()->with('res', ['message' => __('Beneficiary Updated Seccessfully'), 'type' => 'success']);
}

public function destroy(Request $request, Beneficiary $beneficiary)
/**
* Remove the specified resource from storage.
*/
public function destroy(Beneficiary $beneficiary)
{
if (!$this->user->is_permitted_to('delete', Beneficiary::class, $request))
return response()->json(['message' => 'not_permitted'], 422);
$beneficiary->delete();

return new BeneficiaryResource($beneficiary);
return back()->with('res', ['message' => __('Beneficiary Deleted Seccessfully'), 'type' => 'success']);
}
}
13 changes: 0 additions & 13 deletions app/Http/Controllers/DashboardController.php

This file was deleted.

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

namespace App\Http\Controllers;

use App\Models\Item;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreItemRequest;
use App\Http\Requests\UpdateItemRequest;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Inertia\Inertia;


class ItemController extends Controller
{
public static function routeName(){
return Str::snake("Item");
}
public function __construct(Request $request)
{
parent::__construct($request);
}

/**
* Display a listing of the resource.
*/
public function index(Request $request)
{

return Inertia::render(Str::studly("Item").'/Index', [
"headers" => Item::headers(),
"items" => Item::search($request)->sort($request)->paginate($this->pagination),

]);
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
return Inertia::render(Str::studly("Item").'/Create', [
// 'options' => $regions
]);
}

/**
* Store a newly created resource in storage.
*/
public function store(StoreItemRequest $request)
{
$data = $request->validated();
Item::create($data);

return to_route($this->routeName() . '.index')->with('res', ['message' => __('Item Saved Seccessfully'), 'type' => 'success']);
}

/**
* Display the specified resource.
*/
// public function show(Item $item)
// {
//
// }

/**
* Show the form for editing the specified resource.
*/
public function edit(Item $item)
{
return Inertia::render(Str::studly("Item").'/Update', [
//'options' => $regions,
'item' => $item->toArray()
]);
}

/**
* Update the specified resource in storage.
*/
public function update(UpdateItemRequest $request, Item $item)
{
$validated = $request->validated();

$item->update($validated);
return back()->with('res', ['message' => __('Item Updated Seccessfully'), 'type' => 'success']);
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Item $item)
{
$item->delete();
return back()->with('res', ['message' => __('Item Deleted Seccessfully'), 'type' => 'success']);
}
}
Loading
Loading