Blogger Information
Blog 33
fans 0
comment 0
visits 19804
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
laravel框架学习--php培训九期线上班
取个名字真难
Original
678 people have browsed it

\laravel\app\Http\Controllers\Home.php文件内容

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Support\Facades\DB;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\View\View;
  6. class Home extends Controller
  7. {
  8. // 原生查询
  9. function mySele()
  10. {
  11. $data=DB::select('select * from article ');
  12. return view('index',['data'=>$data]);
  13. }
  14. // 用查询构造器
  15. function mySele2(){
  16. $data=DB::table('article')->where('id','>','5')->get();
  17. return view('index',['data'=>$data]);
  18. }
  19. //原生插入
  20. function myErt(){
  21. $data2=DB::insert ('insert into article (id,title) values(11,"新插入进来的") ');
  22. return view('index',['data2'=>$data2]);
  23. }
  24. //用插入构造器
  25. function myErt2()
  26. {
  27. $data2 = DB::table('article')->insert(['id' => 9, 'title' => '新来的']);
  28. return view('index',['data2'=>$data2]);
  29. }
  30. //原生更新
  31. function myUp(){
  32. $data3=DB::update('update article set title ="我是行进过update过的" where id > 8');
  33. return view('index',['data3'=>$data3]);
  34. }
  35. ///用构造器更新
  36. function myUp2(){
  37. $data3=DB::table('article')->where('id',9)->update(['title'=>'uadate更新来的']);
  38. return view('index',['data3'=>$data3]);
  39. }
  40. // 原生删除
  41. function myDe(){
  42. $data4=DB::delete('delete from article where id>8 ');
  43. return view('index',['data4'=>$data4]);
  44. }
  45. ///用构造器删除
  46. function myDe2(){
  47. $data4=DB::table('article')->where('id','>','8')->delete();
  48. return view('index',['data4'=>$data4]);
  49. }
  50. }

\laravel\resources\views\index.blade.php文件内容

  1. <div>
  2. <p>输出如果id>3就输出title否者就输出id</p>
  3. @foreach($data as $id)
  4. @if($id->id>3)
  5. <p>{{$id->id}}</p>
  6. @else
  7. <p>{{$id->title}}</p>
  8. @endif
  9. @endforeach

\laravel\routes\web.php文件内容

  1. <?php
  2. Route::get('/show','Home@mySele');
  3. Route::get('/show2','Home@mySele2');
  4. Route::get('/myinsert','Home@myErt');
  5. Route::get('/myinsert2','Home@myErt2');
  6. Route::get('/myUp','Home@myUp');
  7. Route::get('/myUp2','Home@myUp2');
  8. Route::get('/myDe','Home@myDe');
  9. Route::get('/myDe2','Home@myDe2');
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:完成的相当 OK
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post