RestoTable.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\RestoTables;
  5. use Auth;
  6. class RestoTable extends Controller
  7. {
  8. //
  9. public function restoTables(){
  10. $tables = RestoTables::whereNull('deleted_at')->where('resto_id',Auth::user()->restaurants->id)->orderBy('name','ASC')->get();
  11. $data = [
  12. 'tables' => $tables
  13. ];
  14. return view('tables.tables',$data);
  15. }
  16. public function new_table(){
  17. return view('tables.table_form');
  18. }
  19. public function save(Request $request)
  20. {
  21. // dd($request->all());
  22. $id = $request->id;
  23. if(empty($id))
  24. $table = new RestoTables();
  25. else
  26. $table = RestoTables::find($id);
  27. $table->name = $request->name;
  28. $table->is_active =1;
  29. $table->resto_id = Auth::user()->role=="restaurant"?Auth::user()->restaurants->id:0;
  30. $table->save();
  31. $id = $table->id;
  32. if($id > 0)
  33. echo json_encode(array('type' => 'success', 'message'=>"Table is saved successfully."));
  34. else
  35. echo json_encode(array('type' => 'error', 'message'=>"Table is not saved successfully."));
  36. }
  37. public function delete($id){
  38. //$id = CommonMethods::decrypt($id);
  39. $table = RestoTables::find($id);
  40. $table->deleted_at = date('Y-m-d H:i:s');
  41. $table->save();
  42. }
  43. public function edit($id){
  44. $table = RestoTables::find($id);
  45. $data = [
  46. 'table' => $table,
  47. ];
  48. return view('tables.table_form',$data);
  49. }
  50. }