-
Notifications
You must be signed in to change notification settings - Fork 1
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
35 changed files
with
1,018 additions
and
36 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 |
---|---|---|
|
@@ -18,3 +18,4 @@ yarn-error.log | |
/.fleet | ||
/.idea | ||
/.vscode | ||
deploy.sh |
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,89 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Requests\StoreItemRequest; | ||
use App\Http\Requests\UpdateItemRequest; | ||
use App\Models\Item; | ||
use Inertia\Inertia; | ||
use Vinkla\Hashids\Facades\Hashids; | ||
|
||
class ItemController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
*/ | ||
public function index() | ||
{ | ||
return Inertia::render('Items/Index', [ | ||
'items' => Item::all()->each(function ($item) { | ||
$item->hashid = $item->public_id; | ||
}), | ||
]); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
*/ | ||
public function create() | ||
{ | ||
return Inertia::render('Items/Edit', []); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
*/ | ||
public function store(StoreItemRequest $request) | ||
{ | ||
Item::create([ | ||
'name' => $request->name, | ||
'description' => $request->description, | ||
]); | ||
|
||
return redirect(route('items.index')); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
*/ | ||
public function show(String $hashid) | ||
{ | ||
$id = Hashids::decode($hashid); | ||
$item = Item::query()->where('id', $id)->firstOrFail(); | ||
$item->hashid = $item->public_id; | ||
return Inertia::render('Items/Show', [ | ||
'item' => $item, | ||
]); | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
*/ | ||
public function edit(Int $id) | ||
{ | ||
return Inertia::render('Items/Edit', [ | ||
'item' => Item::findorFail($id), | ||
]); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
*/ | ||
public function update(StoreItemRequest $request, int $id) | ||
{ | ||
$item = Item::findOrFail($id); | ||
$item->update([ | ||
'name' => $request->name, | ||
'description' => $request->description, | ||
]); | ||
return redirect(route('items.index')); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
*/ | ||
public function destroy(Item $item) | ||
{ | ||
// | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class StoreItemRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return Auth::check(); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
//name and description are required | ||
'name' => ['required'], | ||
'description' => ['required'], | ||
]; | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class UpdateItemRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return Auth::check(); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Vinkla\Hashids\Facades\Hashids; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Item extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'name', | ||
'description', | ||
]; | ||
|
||
public function resolveRouteBinding($value, $field = null) | ||
{ | ||
return $this::findOrFail(Hashids::decode($value)); | ||
} | ||
|
||
public function getPublicIdAttribute(): string | ||
{ | ||
return Hashids::encode($this->id); | ||
} | ||
|
||
|
||
} |
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,66 @@ | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\Models\Item; | ||
use App\Models\User; | ||
use Illuminate\Auth\Access\Response; | ||
|
||
class ItemPolicy | ||
{ | ||
/** | ||
* Determine whether the user can view any models. | ||
*/ | ||
public function viewAny(User $user): bool | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can view the model. | ||
*/ | ||
public function view(User $user, Item $item): bool | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can create models. | ||
*/ | ||
public function create(User $user): bool | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can update the model. | ||
*/ | ||
public function update(User $user, Item $item): bool | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can delete the model. | ||
*/ | ||
public function delete(User $user, Item $item): bool | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can restore the model. | ||
*/ | ||
public function restore(User $user, Item $item): bool | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can permanently delete the model. | ||
*/ | ||
public function forceDelete(User $user, Item $item): bool | ||
{ | ||
// | ||
} | ||
} |
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
Oops, something went wrong.