Guest User

Untitled

a guest
Jan 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. {!! Form::open(array('route' => ['createoffice', $id], 'class' => 'form')) !!}
  2. <div class="container">
  3.  
  4. <div class="form-group">
  5. {!! Form::label('Office Name') !!}
  6. {!! Form::text('officename', null, array('required',
  7. 'class'=>'form-control',
  8. 'placeholder'=>'Office Name')) !!}
  9. </div>
  10. <div class="form-group">
  11. {!! Form::label('Office Floor') !!}
  12. <div class="form-group">
  13. {!! Form::label('Office Floor') !!}
  14. {!! Form::select('floor', ['Basement', '1st floor', '2nd floor', '3rd floor', '4th floor'], ['class' => 'form-control']) !!}
  15.  
  16.  
  17. </div>
  18.  
  19.  
  20. <div class="form-group">
  21.  
  22. {!! Form::submit('Create Office',
  23. array('class'=>'btn btn-primary')) !!}
  24.  
  25.  
  26. <a href="{{ url('building/' . $id) }}" class="btn btn-info">
  27. <span class="glyphicon glyphicon-arrow-left"></span> Back
  28. </a>
  29.  
  30. </div>
  31. {!! Form::close() !!}
  32.  
  33. class OfficeController extends Controller
  34. {
  35.  
  36. public function index()
  37. {
  38.  
  39. $search = Request::get('search');
  40. $offices = Office::where('name','LIKE','%'.$search.'%')->get();
  41. return view('search',compact('offices','search'));
  42. }
  43.  
  44. public function create($id)
  45. {
  46.  
  47. return view('createoffice')->with('id', $id);
  48. }
  49.  
  50. public function store(Request $request, $id)
  51. {
  52. $office = new Office();
  53. $office->name =$request->officename;
  54. $office->floor = $request->floor;
  55. $office->building_id = $id;
  56. $office->save();
  57.  
  58. Session::flash('building_flash', 'Created successfully!');
  59.  
  60. return redirect()->route('building', $id);
  61. }
  62.  
  63. public function show($id)
  64. {
  65.  
  66. $office = Office::find($id);
  67. $building = Building::where('id', '=', $office->building_id)->firstOrFail();
  68. return view('office',['building' => $building, 'office' => $office]);
  69.  
  70. }
  71.  
  72. public function edit($id, $office_id) {
  73.  
  74.  
  75. $office = Office::find($office_id);
  76. return view('editoffice', compact('office', 'id'));
  77. }
  78. public function update(Request $request, $id, $office_id)
  79. {
  80.  
  81. $office = Office::find($office_id);
  82. $office->name = $request->officename;
  83. $office->floor = $request->floor;
  84. $office->update();
  85.  
  86. Session::flash('building_flash', 'Updated successfully!');
  87.  
  88. return redirect()->route('building', $id);
  89.  
  90. }
  91.  
  92. public function destroy($office_id)
  93. {
  94. $office = Office::find($office_id);
  95. $office->delete();
  96.  
  97. Session::flash('building_flash_delete', 'Deleted successfully!');
  98.  
  99. return redirect()->back();
  100.  
  101. }
  102. }
Add Comment
Please, Sign In to add comment