PATH:
home
/
lab2454c
/
westernclear.net
/
app
/
Http
/
Controllers
/
Admin
/
Home
<?php namespace App\Http\Controllers\Admin\Home; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; use Illuminate\Http\File; use App\Models\InvestmentSection; use App\Models\InvestmentTextSection; class InvestmentSectionController extends Controller { public function __construct() { $this->middleware('auth:admin'); } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $data['investmentText'] = InvestmentTextSection::first(); $data['investmentSections'] = InvestmentSection::all(); return view('admin.homepageManager.investmentSection.list', $data); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { return view('admin.homepageManager.investmentSection.create'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $values = $request->validate([ "icon"=>'required|image|max:2000', "dark_icon"=>'nullable|image|max:2000', "title"=>'required|string|max:100', "short_description"=>'nullable|string|max:400', ]); if (isset($values['icon'])) { $values['icon'] = Storage::putFile('public/homeImages', new File($request->icon)); } if (isset($values['dark_icon'])) { $values['dark_icon'] = Storage::putFile('public/homeImages', new File($request->dark_icon)); } $investmentSection = new InvestmentSection(); $investmentSection->fill($values); $investmentSection->save(); $notify[] = ['success', 'Investment Section is added!']; return redirect()->route('investmentSection.index')->withNotify($notify); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(InvestmentSection $investmentSection) { $data['investmentSection'] = $investmentSection; return view('admin.homepageManager.investmentSection.edit', $data); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, InvestmentSection $investmentSection) { $changed = false; $values = $request->validate([ "icon"=>'nullable|image|max:2000', "dark_icon"=>'nullable|image|max:2000', "title"=>'required|string|max:100', "short_description"=>'nullable|string|max:400', ]); if ($request->icon) { if (!empty($investmentSection->dark_icon)) { Storage::delete($investmentSection->dark_icon); } $values['icon'] = Storage::putFile('public/homeImages', new File($request->icon)); } if ($request->dark_icon) { if (!empty($investmentSection->dark_icon)) { Storage::delete($investmentSection->dark_icon); } $values['dark_icon'] = Storage::putFile('public/homeImages', new File($request->dark_icon)); } $investmentSection->fill($request->except(['icon','dark_icon'])); if (isset($values['icon'])) { $investmentSection->icon = $values['icon']; } if (isset($values['dark_icon'])) { $investmentSection->dark_icon = $values['dark_icon']; } if ($investmentSection->isDirty()) { $investmentSection->save(); $changed = true; } if (! $changed) { $notify[] = ['warning', 'No changes done to save']; return redirect()->route('investmentSection.index')->withNotify($notify); } $notify[] = ['success', 'Investment Section is Updated!']; return redirect()->route('investmentSection.index')->withNotify($notify); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(InvestmentSection $investmentSection) { if (isset($investmentSection)) { $investmentSection->delete(); if (isset($investmentSection->icon)) { Storage::delete($investmentSection->icon); } } $notify[] = ['success', 'Investment Section is Deleted!']; return redirect()->route('investmentSection.index')->withNotify($notify); } public function textEdit() { $data['investmentText'] = InvestmentTextSection::first(); return view('admin.homepageManager.investmentSection.text.edit', $data); } public function textUpdate(Request $request) { $investmentText = InvestmentTextSection::first(); $changed = false; $values = $request->validate([ "title" => 'required|string|max:100', "description" => 'nullable|string|max:2000', ]); $investmentText->fill($values); if ($investmentText->isDirty()) { $investmentText->save(); $changed = true; } if (! $changed) { $notify[] = ['warning', 'No changes done to save']; return redirect()->route('investmentSection.index')->withNotify($notify); } $notify[] = ['success', 'Investment Text is Updated!']; return redirect()->route('investmentSection.index')->withNotify($notify); } }
[+]
..
[-] InvestmentSectionController.php
[edit]
[-] UnmatchSectionController.php
[edit]
[-] LinkSectionController.php
[edit]
[-] OtherInvestmentSectionController.php
[edit]
[-] GoldstarSectionController.php
[edit]