Blogger Information
Blog 35
fans 3
comment 0
visits 25123
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月30日larave 增删改查
随风
Original
703 people have browsed it

larave 增删改查

web

Route::get('/sel','Article@sel'); Route::get('/sel1','Article@sel1'); Route::get('/sel2','Article@sel2'); Route::get('/sel3','Article@sel3'); Route::get('/myadd','Article@myadd'); Route::get('/myadd1','Article@myadd1'); Route::get('/upd','Article@upd'); Route::get('/upd1','Article@upd1'); Route::get('/mydel','Article@mydel'); Route::get('/mydel1','Article@mydel1');

Article

`namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

// 数据库增、删、查、改。

class Article extends Controller
{
//查 原生
public function sel()
{

  1. $data = DB::select('select * from article where article_id =? ',[10]);
  2. foreach ($data as $k => $v){
  3. $data[$k]=(array)$v;
  4. }
  5. $data =$data[0]
  6. return view ('article/article',['res'=>$data]);
  7. }
  8. public function sel1()
  9. {
  10. $data = DB::table('article')->where('article_id',10)->get()->toArray();
  11. return view('article.article1',['res'=>$data]);
  12. }
  13. public function sel3()
  14. {
  15. $data = DB::table('article')->get()->toArray();
  16. return view('article.article3',['res'=>$data]);
  17. }
  18. public function myadd()
  19. {
  20. $data =DB::insert("insert into article(title,fb_date,soure,ydl,pls,image,detail,cate_id)

values(‘原生插入数据’,’2019-12-31’,’北京’,’11’,’22’,’a.jpg’,’原生插入数据’,’2’)”);
print_r($data);
return view(‘article.article’,[‘res’=>$data]);
}

// 插入 构造器
public function myadd1()
{
$data = DB::table(‘article’)
->insert([‘title’=>’构造器插入数据’,’fb_date’=>’2019-12-31’,
‘soure’=>’北京’,’ydl’=>’22’,’pls’=>’33’,’image’=>’b.gif’,
‘detail’=>’构造器插入数据’,’cate_id’=>’3’]);

  1. print_r($data);
  2. return view('article.article',['res'=>$data]);
  3. }
  4. //修改 原生
  5. public function upd()
  6. {
  7. $data =DB::update("update article set title='原生修改数据' where article_id=29");

//
print_r($data);

  1. return view('article.article',['res'=>$data]);
  2. }

// 修改 构造器
public function upd1()
{
$data =DB::table(‘article’)
->where(‘article_id’,31)
// ->update([‘title’=>’构造器修改数据’]);
->update([‘title’=>’构造器修改数据’,’detail’=>’构造器修改数据’]);

  1. print_r($data);
  2. return view('article.article',['res'=>$data]);
  3. }
  4. // 删除 原生
  5. public function mydel()
  6. {
  7. $data = DB::delete('delete from article where article_id=33');
  8. print_r($data);
  9. return view('article.article', ['res' => $data]);
  10. }

// 删除 构造器
public function mydel1()
{
$data =DB::table(‘article’)
->where(‘article_id’,’34’)
->delete();
print_r($data);

  1. return view('article.article', ['res' => $data]);
  2. }

}`

article3
`
@foreach($res as $v)

  1. @if($v->article_id < 5)
  2. {{$v->title}}.买.<br>
  3. @elseif($v->article_id>5 && $v->article_id<10)
  4. {{$v->title}}.可以买.<br>
  5. @else
  6. {{$v->title}}.不能买.<br>
  7. @endif`
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:写得不错嘛, 继续
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