“晚风吹人醒 万事藏于心 
        我没说不公平 也没说苦 我说我知道了”

laravel 引入模板:

1.return view('admin.login');

2.return view('admin.add',['data'=>$data]);
获取数据:

$request->input('name'); 
查询

use DB;
$res = DB::table('user')->where('name',$name)->first();

$res2 = DB::table('user')->where('name',$name)->where('pass',$pass)->first();

$data = DB::table('order')->where('name','like','%'.$name.'%')->paginate(10);

$data1 = DB::table('order')->where('name','like','%'.$name.'%')->where('status',0)->paginate(10);

$data = DB::table('detail')->where('orderid',$id)->get();

$review = DB::table('review')->where('goodsid',$v->goodsid)->where('orderid',$order->id)->value('review');

$data = DB::table('type')->select(DB::raw("*,concat(path,',',id) as paths"))->where('status','1')->orderBy('paths')->get();

$res = DB::table('type')->where('pid',$v->id)->first();

修改:$res = DB::table('order')->where('id',$id)->update(['status' => 1]);

新增:DB::table('type')->insert($data);


转向:return redirect("/index");返回提示:return back()->with('mess','密码错误');

$request->session()->forget('name');

 

 

laravel sql

1.插入数据

DB::insert('insert into test (id, name, email, password) values (?, ?, ? , ? )',[1, 'Laravel','laravel@test.com','Laravel']);

2.查询语句

$user = DB::select('select * from test where id = ?', [1]);

//我们还 可以看到在执行查询的时候使用了参数绑定,以避免SQL注入。除此之//外还可以使用命名绑定:

$user = DB::select('select * from test where id = :id', [':id'=>1]); 

3.更新语句

$resule = DB::update('update test set name="laraveltest" where name = ?', ['laravel']);

//此处返回值为影响的行数请注意 不能直接做判断的

  if($resule || $resule===0){

    //成功的提示语

    return true;

  }else{

    //失败的提示语

    return false;

  }

4.删除语句

$deleted = DB::delete('delete from test');

posted on 2023-02-14 09:38  诗里刻画的影子  阅读(34)  评论(0编辑  收藏  举报