Skip to content

Commit

Permalink
Fix for select category #37
Browse files Browse the repository at this point in the history
  • Loading branch information
1e4 committed Oct 11, 2019
1 parent 4eb0945 commit 36225d3
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 124 deletions.
6 changes: 6 additions & 0 deletions app/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class Category extends Model

protected $fillable = ['name'];


public function scopeFindBySlug($query, $slug): Category
{
return $query->whereSlug($slug)->firstOrFail();
}

public function sluggable(): array
{
return [
Expand Down
14 changes: 10 additions & 4 deletions app/Http/Controllers/Administration/GameController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function datatables(): JsonResponse
public function create(): View
{
$categories = [];
$categories[0] = "-- Select Category --";
$categories["none__"] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name', 'slug')->toArray());

return view('administration.game.create', compact('categories'));
Expand All @@ -68,11 +68,14 @@ public function create(): View
*/
public function store(CreateGameRequest $request): RedirectResponse
{
$category = Category::findBySlug($request->input('category_id'));

$game = new Game();
$game->fill($request->all('name', 'url', 'description', 'category_id', 'callback_url'));
$game->fill($request->all('name', 'url', 'description', 'callback_url'));
$game->is_pending = $request->has('is_pending') ? false : true;
$game->is_premium = $request->has('is_premium');
$game->uuid = \Str::uuid();
$game->category_id = $category->id;
$game->save();

flash('Game has been created')->success();
Expand Down Expand Up @@ -101,7 +104,7 @@ public function show(Game $game): View
public function edit(Game $game): View
{
$categories = [];
$categories[0] = "-- Select Category --";
$categories["none__"] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name', 'slug')->toArray());

return view('administration.game.edit', compact('game', 'categories'));
Expand All @@ -116,8 +119,11 @@ public function edit(Game $game): View
*/
public function update(CreateGameRequest $request, Game $game): RedirectResponse
{
$game->fill($request->all('name', 'url', 'description', 'category_id', 'callback_url'));
$category = Category::findBySlug($request->input('category_id'));

$game->fill($request->all('name', 'url', 'description', 'callback_url'));
$game->is_premium = $request->has('is_premium');
$game->category_id = $category->id;
$game->slug = null;
$game->save();

Expand Down
10 changes: 8 additions & 2 deletions app/Http/Controllers/GameController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function index(): View
public function create(): View
{
$categories = [];
$categories[0] = "-- Select Category --";
$categories["none__"] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name', 'slug')->toArray());

return view('games.create', compact('categories'));
Expand All @@ -39,10 +39,13 @@ public function show($slug): RedirectResponse
public function store(CreateGameRequest $request): RedirectResponse
{

$category = Category::findBySlug($request->input('category_id'));

$game = new Game();
$game->fill($request->all('name', 'url', 'description', 'category_id', 'callback_url'));
$game->is_pending = true;
$game->is_premium = false;
$game->category_id = $category->id;
$game->uuid = \Str::uuid();

if ($request->has('banner_image')) {
Expand Down Expand Up @@ -72,7 +75,7 @@ public function edit(Game $game): View
{

$categories = [];
$categories[0] = "-- Select Category --";
$categories["none__"] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name', 'slug')->toArray());

$images = ImageUpload::where('game_id', $game->id)->get();
Expand All @@ -92,10 +95,13 @@ public function edit(Game $game): View

public function update(CreateGameRequest $request, Game $game): RedirectResponse
{
$category = Category::findBySlug($request->input('category_id'));

$game->fill($request->all('name', 'url', 'description', 'category_id', 'callback_url'));
$game->is_pending = true;
$game->is_premium = false;
$game->slug = null;
$game->category_id = $category->id;

if ($request->has('banner_image')) {
if ($game->banner_image !== null) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"laracasts/flash": "^3.0",
"laravel/framework": "^6.0",
"laravel/tinker": "^1.0",
"netojose/laravel-bootstrap-4-forms": "^2.0",
"netojose/laravel-bootstrap-4-forms": "^3.0",
"yajra/laravel-datatables-oracle": "~9.0"
},
"require-dev": {
Expand Down
Loading

0 comments on commit 36225d3

Please sign in to comment.