亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Laravel框架實(shí)現(xiàn)簡(jiǎn)單的學(xué)生信息管理平臺(tái)案例【附源碼下載】

 更新時(shí)間:2019年05月07日 10:47:22   作者:Yxh_blogs  
這篇文章主要介紹了Laravel框架實(shí)現(xiàn)簡(jiǎn)單的學(xué)生信息管理平臺(tái),結(jié)合具體案例形式較為詳細(xì)的分析了基于Laravel框架的學(xué)生信息管理平臺(tái)路由與控制器相關(guān)操作技巧,并附帶完整源碼供讀者下載參考,需要的朋友可以參考下

本文實(shí)例講述了Laravel框架實(shí)現(xiàn)簡(jiǎn)單的學(xué)生信息管理平臺(tái)。分享給大家供大家參考,具體如下:

laravel框架寫的簡(jiǎn)易版的學(xué)生信息管理平臺(tái),貫穿了laravel的控制器、視圖、模板、模型、中間件、路由規(guī)則的使用。

頁(yè)面是使用BootStrap前端框架搭建

使用laravel實(shí)現(xiàn)了增刪改查的功能。

代碼下載鏈接在文章底部。

//這是路由文件的關(guān)鍵代碼
Route::group(['middleware' => ['web']], function () {
  Route::get('student/index',['uses'=>'StudentController@index']);
  Route::any('student/create',['uses'=>'StudentController@create']);
  Route::post('student/save',['uses'=>'StudentController@save']);
  Route::any('student/update/{id}',['uses'=>'StudentController@update']);
  Route::any('student/detail/{id}',['uses'=>'StudentController@detail']);
  Route::any('student/delete/{id}',['uses'=>'StudentController@delete']);
});

//控制器文件的關(guān)鍵代碼,增刪改查
class StudentController extends Controller{
  //學(xué)生列表
  public function index(){
    $students = Student::paginate(20);
    //dd($students);
    return view('student.index',[
      'students'=>$students,
    ]);
  }
  //新增頁(yè)面
  public function create(Request $request){
    $student = new Student();
    if($request->isMethod('POST')){
      //1.控制器驗(yàn)證
      /*$this->validate($request,[
        'Student.name'=>'required|min:2|max:20',
        'Student.age' =>'required|integer',
        'Student.sex' =>'required|integer',
      ],[
        'required'=>':attribute 為必填項(xiàng)',
        'min'=>':attribute長(zhǎng)度不符合要求',
        'integer'=>':attribute必須為整數(shù)',
      ],[
        'Student.name'=>'姓名',
        'Student.age' =>'年齡',
        'Student.sex' =>'性別'
      ]);*/
      //2.Validator類驗(yàn)證
      $validator = \Validator::make($request->input(),[
        'Student.name'=>'required|min:2|max:20',
        'Student.age' =>'required|integer',
        'Student.sex' =>'required|integer',
      ],[
        'required'=>':attribute 為必填項(xiàng)',
        'min'=>':attribute長(zhǎng)度不符合要求',
        'integer'=>':attribute必須為整數(shù)',
      ],[
        'Student.name'=>'姓名',
        'Student.age' =>'年齡',
        'Student.sex' =>'性別'
      ]);
      //withInput保持?jǐn)?shù)據(jù)
      if($validator->fails()){
        return redirect()->back()->withErrors($validator)->withInput();
      }
      $data = $request->input('Student');
      if(Student::create($data)){
        return redirect('student/index')->with('success','添加成功');
      }else{
        return redirect()->back();
      }
    }
    return view('student.create',[
      'student'=>$student,
    ]);
  }
  //保存數(shù)據(jù)操作
  public function save(Request $request){
    $data = $request->input('Student');
    $student = new Student();
    $student->name = $data['name'];
    $student->age = $data['age'];
    $student->sex = $data['sex'];
    if($student->save()){
      return redirect('student/index');
    }else{
      return redirect()->back();
    }
  }
  //更新數(shù)據(jù)操作
  public function update(Request $request,$id){
    $student = Student::find($id);
    if($request->isMethod('POST')){
      //Validator類驗(yàn)證
      $validator = \Validator::make($request->input(),[
        'Student.name'=>'required|min:2|max:20',
        'Student.age' =>'required|integer',
        'Student.sex' =>'required|integer',
      ],[
        'required'=>':attribute 為必填項(xiàng)',
        'min'=>':attribute長(zhǎng)度不符合要求',
        'integer'=>':attribute必須為整數(shù)',
      ],[
        'Student.name'=>'姓名',
        'Student.age' =>'年齡',
        'Student.sex' =>'性別'
      ]);
      //withInput保持?jǐn)?shù)據(jù)
      if($validator->fails()){
        return redirect()->back()->withErrors($validator)->withInput();
      }
      $data = $request->input('Student');
      $student->name = $data['name'];
      $student->age = $data['age'];
      $student->sex = $data['sex'];
      if($student->save()){
        return redirect('student/index')->with('success','修改成功-'.$id);
      }
    }
    return view('student.update',[
      'student'=>$student,
    ]);
  }
  //信息詳情
  public function detail($id){
    $student = Student::find($id);
    return view('student.detail',[
      'student'=>$student,
    ]);
  }
  //刪除操作
  public function delete($id){
    $student = Student::find($id);
    if($student->delete()){
      return redirect('student/index')->with('success','刪除成功-'.$id);
    }else{
      return redirect('student/index')->with('error','刪除失敗-'.$id);
    }
  }
}

下面是效果展示

學(xué)生列表頁(yè)

新增頁(yè)面

詳情頁(yè)面

修改頁(yè)面

完整實(shí)例代碼點(diǎn)擊此處本站下載。

更多關(guān)于Laravel相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門與進(jìn)階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家基于Laravel框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Laravel使用支付寶進(jìn)行支付的示例代碼

    Laravel使用支付寶進(jìn)行支付的示例代碼

    本篇文章主要介紹了Laravel使用支付寶進(jìn)行支付的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08
  • 在laravel中使用with實(shí)現(xiàn)動(dòng)態(tài)添加where條件

    在laravel中使用with實(shí)現(xiàn)動(dòng)態(tài)添加where條件

    今天小編就為大家分享一篇在laravel中使用with實(shí)現(xiàn)動(dòng)態(tài)添加where條件,具有好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • thinkphp5框架路由原理與用法詳解

    thinkphp5框架路由原理與用法詳解

    這篇文章主要介紹了thinkphp5框架路由原理與用法,結(jié)合圖文與實(shí)例形式詳細(xì)分析了thinkPHP5框架路由的相關(guān)原理、使用方法及操作注意事項(xiàng),需要的朋友可以參考下
    2020-02-02
  • typecho插件編寫教程(五):核心代碼

    typecho插件編寫教程(五):核心代碼

    這篇文章主要介紹了typecho插件編寫教程(五):核心代碼,本文講解了完整的插件核心代碼的示例,需要的朋友可以參考下
    2015-05-05
  • Yii2框架中使用PHPExcel導(dǎo)出Excel文件的示例

    Yii2框架中使用PHPExcel導(dǎo)出Excel文件的示例

    本篇文章主要介紹了Yii2框架中使用PHPExcel導(dǎo)出Excel文件的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • php 提速工具eAccelerator 配置參數(shù)詳解

    php 提速工具eAccelerator 配置參數(shù)詳解

    php 提速工具eAccelerator 配置參數(shù)詳解,需要的朋友可以參考下。
    2010-05-05
  • Laravel5.6框架使用CKEditor5相關(guān)配置詳解

    Laravel5.6框架使用CKEditor5相關(guān)配置詳解

    這篇文章主要介紹了Laravel5.6框架使用CKEditor5相關(guān)配置,結(jié)合實(shí)例形式詳細(xì)分析了Laravel5.6框架整合CKEditor5編輯器相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下
    2019-07-07
  • PHP實(shí)現(xiàn)會(huì)員注冊(cè)系統(tǒng)

    PHP實(shí)現(xiàn)會(huì)員注冊(cè)系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了PHP實(shí)現(xiàn)會(huì)員注冊(cè)系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • laravel 框架結(jié)合關(guān)聯(lián)查詢 when()用法分析

    laravel 框架結(jié)合關(guān)聯(lián)查詢 when()用法分析

    這篇文章主要介紹了laravel 框架結(jié)合關(guān)聯(lián)查詢 when()用法,結(jié)合實(shí)例形式分析了laravel5.6框架when()基本原理、使用方法及操作注意事項(xiàng),需要的朋友可以參考下
    2019-11-11
  • 談?wù)?PHP7新增功能

    談?wù)?PHP7新增功能

    php7發(fā)布已有半月,最近有時(shí)間了解一下php7的新特性,當(dāng)然,這個(gè)版本最大的特點(diǎn)是性能的提升,對(duì)php7 新增功能的相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12

最新評(píng)論