Skip to content
Permalink
Browse files

add category to rooms, for suite, deluxe, standard

  • Loading branch information...
Tim S Tim S
Tim S authored and Tim S committed May 25, 2019
1 parent 9a42cc4 commit 109b4427fea672e04310a9303c40e938b4a32a4e
@@ -0,0 +1,10 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
protected $fillable = ['name'];
}
@@ -0,0 +1,150 @@
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Gate;
use App\Ctegory;
use App\Category;
use App\Http\Requests\Admin\UpdateCategoriesRequest;
use App\Http\Requests\Admin\StoreCategoriesRequest;
class CategoryController extends Controller
{
public function index()
{
$categories=Category::all();
return view('admin.categories.index', compact('categories'));
}
public function create()
{
//show template
return view('admin.categories.create');
}
public function store(StoreCategoriesRequest $request)
{
if (! Gate::allows('category_create')) {
return abort(401);
}
$category = Category::create([
'name'=> $request->name
]);
return redirect('/admin/categories');
}
/**
* Show the form for editing category.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
if (! Gate::allows('category_edit')) {
return abort(401);
}
$category = Category::findOrFail($id);
return view('admin.categories.edit', compact('category'));
}
/**
* Update category in storage.
*
* @param \App\Http\Requests\UpdateCountriesRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(UpdateCategoriesRequest $request, $id)
{
if (! Gate::allows('category_edit')) {
return abort(401);
}
$category = Category::findOrFail($id);
$category->update($request->all());
return redirect()->route('admin.categories.index');
}
/**
* Remove Booking from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
if (!Gate::allows('category_delete')) {
return abort(401);
}
$booking = Category::findOrFail($id);
$booking->delete();
return redirect()->route('admin.categories.index');
}
/**
* Delete all selected Category at once.
*
* @param Request $request
*/
public function massDestroy(Request $request)
{
if (!Gate::allows('booking_delete')) {
return abort(401);
}
if ($request->input('ids')) {
$entries = Category::whereIn('id', $request->input('ids'))->get();
foreach ($entries as $entry) {
$entry->delete();
}
}
}
/**
* Restore Category from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function restore($id)
{
if (!Gate::allows('booking_delete')) {
return abort(401);
}
$booking = Category::onlyTrashed()->findOrFail($id);
$booking->restore();
return redirect()->route('admin.bookings.index');
}
/**
* Permanently delete Category from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function perma_del($id)
{
if (!Gate::allows('booking_delete')) {
return abort(401);
}
$booking = Category::onlyTrashed()->findOrFail($id);
$booking->forceDelete();
return redirect()->route('admin.bookings.index');
}
}
@@ -8,6 +8,7 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\StoreRoomsRequest;
use App\Http\Requests\Admin\UpdateRoomsRequest;
use App\Category;
class RoomsController extends Controller
{
@@ -45,7 +46,9 @@ public function create()
if (! Gate::allows('room_create')) {
return abort(401);
}
return view('admin.rooms.create');
$categories = Category::get()->pluck('name', 'id')->prepend(trans('quickadmin.qa_please_select'), '');
return view('admin.rooms.create',compact('categories'));
}
/**
@@ -79,8 +82,9 @@ public function edit($id)
return abort(401);
}
$room = Room::findOrFail($id);
$categories = Category::get()->pluck('name', 'id')->prepend(trans('quickadmin.qa_please_select'), '');
return view('admin.rooms.edit', compact('room'));
return view('admin.rooms.edit', compact('room','categories'));
}
/**
@@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
class StoreCategoriesRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
];
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
class UpdateCategoriesRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
];
}
}
@@ -141,6 +141,17 @@ public function boot()
Gate::define('find_room_access', function ($user) {
return in_array($user->role_id, [1, 2]);
});
// Auth gates for: add category
Gate::define('category_create', function ($user) {
return in_array($user->role_id, [1]);
});
// Auth gates for: add category
Gate::define('category_edit', function ($user) {
return in_array($user->role_id, [1]);
});
Gate::define('category_delete', function ($user) {
return in_array($user->role_id, [1]);
});
}
}
@@ -17,7 +17,7 @@ class Room extends Model
{
use SoftDeletes;
protected $fillable = ['room_number', 'floor', 'description'];
protected $fillable = ['room_number', 'floor', 'description','category_id'];
/**
* Set attribute to money format
@@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('categories');
}
}
@@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddCategoryRooms extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('rooms', function (Blueprint $table) {
$table->integer('category_id')->unsigned();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('rooms', function (Blueprint $table) {
$table->dropColumn('category_id');
});
}
}
@@ -34,6 +34,13 @@
'name' => 'Name',
],
],
'categories' => [
'title' => 'Categories',
'fields' => [
'title' => 'Title',
'name' => 'Name',
],
],
'customers' => [
'title' => 'Customers',
@@ -52,6 +59,7 @@
'fields' => [
'room-number' => 'Room number',
'floor' => 'Floor',
'category' => 'Category',
'description' => 'Description',
'actions' => 'Actions',
],

0 comments on commit 109b442

Please sign in to comment.
You can’t perform that action at this time.