php—根据批处理开始和结束日期以及时间从数据库中获取数据

izkcnapc  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(198)

我是一个新的发展和我的工作在学校的企业资源规划的拉威尔。我有一个表facultybatches,它包含以下列:
id,subject,facultyid,startat,endat,batchstatus,remark,batchtime
这个表格包含了关于教师和他们将要学习的批次的数据,现在我需要确保同一个老师不会在同一时间学习不同的批次,如果时间相同,那么应该有不同的开始和结束日期。
最合适的方法是什么。
我的控制器;

<?php

namespace App\Http\Controllers;
use Illuminate\Validation\Validator;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use Session;

class FacultyBatchController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        // $faculties = DB::table('facultybatches')->get();
        $faculties = DB::table('facultybatches')
        ->join('faculty','facultybatches.facultyId' , '=' ,'faculty.facultyId')
        ->join('course','facultybatches.subject' , '=' ,'course.id')
        ->select('faculty.name','facultybatches.*','course.name AS course_name')->get();    
        // return $some;
        return view('services.viewfacultybatch',compact('faculties'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $courses = DB::select('select id,name from course');
        $faculties = DB::select('select facultyId,name from faculty');
        return view('services.addfacultybatch',compact('faculties','courses'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        if($request->isMethod('POST')){
            $this->validate($request,[
                'facultyId' => 'required',
                'subjectname' => 'required',
                'startdate' => 'required',
                'enddate' => 'required',
                'batchStatus' => 'required',
                'remark' => 'required',
                'batchTime' => 'required'
                ]);

            // WHAT SHOULD I WRITE HERE

            return redirect()->route('facultybatch.index');

        }
    }

    /**
     * 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)
    {
        $batch = DB::table('facultybatches')->where('id', $id)->first();

        $courses = DB::select('select id,name from course');
        $faculties = DB::select('select facultyId,name from faculty');

        return view('services.editfacultybatch',compact('faculties','courses','batch'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        if($request->isMethod('PUT')){
            $this->validate($request,[
                'facultyId' => 'required',
                'subjectname' => 'required',
                'startdate' => 'required',
                'enddate' => 'required',
                'batchStatus' => 'required',
                'remark' => 'required',
                'batchTime' => 'required'
                ]);

                DB::table('facultybatches')->where('id',$id)->update(    
                ['facultyId' => $request->facultyId,'subject' => $request->subjectname,'starAt' => $request->startdate,'endAt' => $request->enddate,'batchStatus' => $request->batchStatus,'remark' => $request->remark,'batchTime' => $request->batchTime]  );

            return redirect()->route('facultybatch.index');

        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {

        DB::delete('DELETE FROM facultybatches
        WHERE id = ?',[$id]);
    return redirect()->route('facultybatch.index');
    }

    public function facultybatchss(Request $request){

        $ids = $request->fb;
        DB::table("facultybatches")->whereIn('id',explode(",",$ids))->delete();

    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题