IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/School/Library/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/School/Library/SourceLanguageController.php

<?php

namespace App\Http\Controllers\School\Library;

use Illuminate\Http\Request;
use App\Http\Controllers\School\SchoolController;
use DB;
use Auth;

class SourceLanguageController extends SchoolController
{
     /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index() {
        $langs = \App\BookSourceLanguage::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idSourceLanguage', 'desc')->get();
        return view('schools.library.source_language', compact('langs'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create() {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request) {
        foreach ($request->languages as $key => $val) {
            $rules['languages.' . $key . '.sourcelangName'] = 'unique:source_language,sourcelangName,NULL,idSourceLanguage,idSchool,' . Auth::guard('school')->user()->idSchool;
        }
        $message = [
            'languages.*sourcelangName.unique' => 'Source Language Already Exist.',
        ];
        $this->Validate($request, $rules, $message);
        foreach ($request->languages as $var) {
            $lang = new \App\BookSourceLanguage();
            $lang->fill($request->all());
            $lang->idSchool = Auth::guard('school')->user()->idSchool;
            $lang->sourcelangName = $var['sourcelangName'];
            $lang->save();
        }
        flash('Source Language has been added successfully!!');
        if ($request->ajax()) {
            return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
        }
        return redirect('school/sourcelang');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id) {
        
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id) {
        $langs = \App\BookSourceLanguage::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idSourceLanguage', 'desc')->get();
        $lang = \App\BookSourceLanguage::where('idSourceLanguage', '=', $id)->first();
        return view('schools.library.source_language', compact('langs', 'lang'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id) {
        $lang = \App\BookSourceLanguage::where('idSourceLanguage', '=', $id)->first();
        $rules = [
            'sourcelangName' => 'required|unique:source_language,sourcelangName,' . $id . ',idSourceLanguage,idSchool,' . Auth::guard('school')->user()->idSchool,
        ];
        $this->validate($request, $rules);
        $lang->fill($request->all());
        $lang->update();
        return redirect('school/sourcelang');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id) {
        $lang = \App\BookSourceLanguage::where('idSourceLanguage', '=', $id)->first();
        $lang->delete();
        return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
    }

}

Copyright © 2021 - 2025 IMMREX7