Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:完成的相当 OK
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\View\View;
class Home extends Controller
{
// 原生查询
function mySele()
{
$data=DB::select('select * from article ');
return view('index',['data'=>$data]);
}
// 用查询构造器
function mySele2(){
$data=DB::table('article')->where('id','>','5')->get();
return view('index',['data'=>$data]);
}
//原生插入
function myErt(){
$data2=DB::insert ('insert into article (id,title) values(11,"新插入进来的") ');
return view('index',['data2'=>$data2]);
}
//用插入构造器
function myErt2()
{
$data2 = DB::table('article')->insert(['id' => 9, 'title' => '新来的']);
return view('index',['data2'=>$data2]);
}
//原生更新
function myUp(){
$data3=DB::update('update article set title ="我是行进过update过的" where id > 8');
return view('index',['data3'=>$data3]);
}
///用构造器更新
function myUp2(){
$data3=DB::table('article')->where('id',9)->update(['title'=>'uadate更新来的']);
return view('index',['data3'=>$data3]);
}
// 原生删除
function myDe(){
$data4=DB::delete('delete from article where id>8 ');
return view('index',['data4'=>$data4]);
}
///用构造器删除
function myDe2(){
$data4=DB::table('article')->where('id','>','8')->delete();
return view('index',['data4'=>$data4]);
}
}
<div>
<p>输出如果id>3就输出title否者就输出id</p>
@foreach($data as $id)
@if($id->id>3)
<p>{{$id->id}}</p>
@else
<p>{{$id->title}}</p>
@endif
@endforeach
<?php
Route::get('/show','Home@mySele');
Route::get('/show2','Home@mySele2');
Route::get('/myinsert','Home@myErt');
Route::get('/myinsert2','Home@myErt2');
Route::get('/myUp','Home@myUp');
Route::get('/myUp2','Home@myUp2');
Route::get('/myDe','Home@myDe');
Route::get('/myDe2','Home@myDe2');