| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\Section;
- use App\SectionAdv;
- use Illuminate\Http\Request;
- use File;
-
- class SectionAdvController extends Controller
- {
-
- protected $rules = [
- // 'name' => ['required']
- ];
- public function index(Section $section)
- {
- if ($section->layout == 'layout_1')
- {
- $aDatas['300x75'] = array();
- $aDatas['300x75 Sotto'] = array();
- $aDatas['300x600'] = array();
- }
- if ($section->layout == 'layout_2')
- {
- $aDatas['300x600'] = array();
- $aDatas['300x75'] = array();
- $aDatas['300x75 Sotto'] = array();
- }
- if ($section->layout == 'layout_3')
- {
- $aDatas['300x600'] = array();
- $aDatas['300x250'] = array();
- }
- if ($section->layout == 'layout_4')
- {
- $aDatas['300x250 Sopra'] = array();
- $aDatas['300x250 Centro'] = array();
- $aDatas['300x250 Sotto'] = array();
- $aDatas['300x250 Quarto'] = array();
- // $aDatas['300x75'] = array();
- }
- if ($section->layout == 'layout_5')
- {
- $aDatas['300x75'] = array();
- $aDatas['300x250 Sopra'] = array();
- $aDatas['300x250 Centro'] = array();
- $aDatas['300x250 Sotto'] = array();
- }
- if ($section->layout == 'layout_6')
- {
- $aDatas['300x250'] = array();
- $aDatas['300x250 Sotto'] = array();
- // $aDatas['300x75'] = array();
- }
- if ($section->layout == 'layout_7')
- {
- $aDatas['300x250 Sopra'] = array();
- $aDatas['300x75 Sopra'] = array();
- $aDatas['300x75 Centro'] = array();
- $aDatas['300x75 Sotto'] = array();
- $aDatas['300x75 Quarto'] = array();
- $aDatas['300x250 Sotto'] = array();
- }
-
- $sections_advs = SectionAdv::where('section_id', '=', $section->id)->orderBy('position')->get();
- foreach($sections_advs as $a)
- {
- if (array_key_exists($a->position, $aDatas))
- $aDatas[$a->position][] = $a;
- }
-
- return view('sections_advs.index',compact('aDatas', 'section'));
- // ->with('i', (request()->input('page', 1) - 1) * 5);
- }
-
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create(Section $section)
- {
- return view('sections_advs.create', compact('section'));
- }
-
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request, Section $section, SectionAdv $section_adv)
- {
- $request->validate($this->rules);
-
- $input = $request->all();
- $input["name"] = $input["name"] == null ? '' : $input["name"];
- $input["online"] = isset($input["online"]) ? ($input["online"] == 'on' ? true : false) : false;
- $input["section_id"] = $section->id;
- if(request()->image)
- {
- $file = request()->image;
- $filename = time() . '_' . $file->getClientOriginalName();
- if (! File::exists(public_path()."/files/adv"))
- File::makeDirectory(public_path()."/files/adv");
-
- $path = public_path('files/adv');
- request()->image->move($path, $filename);
- $input["image"] = $filename;
- }
- if(request()->jingle)
- {
- $file = request()->jingle;
- $filename = time() . '_' . $file->getClientOriginalName();
- if (! File::exists(public_path()."/files/adv"))
- File::makeDirectory(public_path()."/files/adv");
-
- $path = public_path('files/news');
- request()->jingle->move($path, $filename);
- $input["jingle"] = $filename;
- }
- SectionAdv::create($input);
-
- return redirect()->route('sections.advs.index', compact('section'))
- ->with('success','Section created successfully.');
- }
-
- /**
- * Display the specified resource.
- *
- * @param \App\Section $section
- * @return \Illuminate\Http\Response
- */
- public function show(SectionAdv $section_adv, Section $section)
- {
- return view('sections_advs.show',compact('section'));
- }
-
- /**
- * Show the form for editing the specified resource.
- *
- * @param \App\Section $section
- * @return \Illuminate\Http\Response
- */
- public function edit(Section $section, SectionAdv $adv)
- {
- return view('sections_advs.edit',compact('section', 'adv'));
- }
-
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param \App\Section $section
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, Section $section, SectionAdv $adv)
- {
- $request->validate($this->rules);
-
- $input = $request->all();
- $input["name"] = $input["name"] == null ? '' : $input["name"];
- $input["online"] = isset($input["online"]) ? ($input["online"] == 'on' ? true : false) : false;
- if(request()->image)
- {
- $file = request()->image;
- $filename = time() . '_' . $file->getClientOriginalName();
- if (! File::exists(public_path()."/files/adv"))
- File::makeDirectory(public_path()."/files/adv");
-
- $path = public_path('files/adv');
- request()->image->move($path, $filename);
- $input["image"] = $filename;
- }
- if(request()->jingle)
- {
- $file = request()->jingle;
- $filename = time() . '_' . $file->getClientOriginalName();
- if (! File::exists(public_path()."/files/adv"))
- File::makeDirectory(public_path()."/files/adv");
-
- $path = public_path('files/news');
- request()->jingle->move($path, $filename);
- $input["jingle"] = $filename;
- }
- $adv->update($input);
-
- return redirect()->route('sections.advs.index', compact('section'))
- ->with('success','Section adv updated successfully');
- }
-
- /**
- * Remove the specified resource from storage.
- *
- * @param \App\Section $section
- * @return \Illuminate\Http\Response
- */
- public function destroy(Section $section, SectionAdv $adv)
- {
- $adv->delete();
-
- return redirect()->route('sections.advs.index', compact('section'))
- ->with('success','Section adv deleted successfully');
- }
- }
|