SliderController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Slider;
  5. class SliderController extends Controller
  6. {
  7. /**
  8. * Display a listing of the resource.
  9. *
  10. * @return \Illuminate\Http\Response
  11. */
  12. public function index()
  13. {
  14. $sliders = Slider::all();
  15. return view('sliders.index', compact('sliders'));
  16. }
  17. /**
  18. * Show the form for creating a new resource.
  19. *
  20. * @return \Illuminate\Http\Response
  21. */
  22. public function create()
  23. {
  24. return view('sliders.create');
  25. }
  26. /**
  27. * Store a newly created resource in storage.
  28. *
  29. * @param \Illuminate\Http\Request $request
  30. * @return \Illuminate\Http\Response
  31. */
  32. public function store(Request $request)
  33. {
  34. if($request->hasFile('photos')){
  35. foreach ($request->photos as $key => $photo) {
  36. $slider = new Slider;
  37. $slider->link = $request->url;
  38. $slider->photo = $photo->store('uploads/sliders');
  39. $slider->save();
  40. }
  41. flash(translate('Slider has been inserted successfully'))->success();
  42. }
  43. return redirect()->route('home_settings.index');
  44. }
  45. /**
  46. * Display the specified resource.
  47. *
  48. * @param int $id
  49. * @return \Illuminate\Http\Response
  50. */
  51. public function show($id)
  52. {
  53. //
  54. }
  55. /**
  56. * Show the form for editing the specified resource.
  57. *
  58. * @param int $id
  59. * @return \Illuminate\Http\Response
  60. */
  61. public function edit($id)
  62. {
  63. //
  64. }
  65. /**
  66. * Update the specified resource in storage.
  67. *
  68. * @param \Illuminate\Http\Request $request
  69. * @param int $id
  70. * @return \Illuminate\Http\Response
  71. */
  72. public function update(Request $request, $id)
  73. {
  74. $slider = Slider::find($id);
  75. $slider->published = $request->status;
  76. if($slider->save()){
  77. return '1';
  78. }
  79. else {
  80. return '0';
  81. }
  82. }
  83. /**
  84. * Remove the specified resource from storage.
  85. *
  86. * @param int $id
  87. * @return \Illuminate\Http\Response
  88. */
  89. public function destroy($id)
  90. {
  91. $slider = Slider::findOrFail($id);
  92. if(Slider::destroy($id)){
  93. //unlink($slider->photo);
  94. flash(translate('Slider has been deleted successfully'))->success();
  95. }
  96. else{
  97. flash(translate('Something went wrong'))->error();
  98. }
  99. return redirect()->route('home_settings.index');
  100. }
  101. }