'fengyunshan',
'age' => '123',
'gender' => '1',
];
dump(DB::table('ceshi')->insert($dats));
}
public function get()
{
//取出基本数据
// $data = DB::table('ceshi')->get();
// foreach ($data as $v){
// dump($v->name);
// }
//取出id>2的数据
// $data = DB::table('ceshi')->where('id','>','2')->get();
//取出id>2,且年龄小于25的记录
// $data = DB::table('ceshi')->where('id','>','2')->where('age','<','25')->get();
//返回一条数据
// $data = DB::table('ceshi')->first();
//查询单个字段的值
// $data = DB::table('ceshi')->where(id,'=','1')value('name');
//查询指定字段的值
// $data = DB::table('ceshi')->select('name','age','gender')->where("id",'=','1')->get();
//查询数据排序
// $data = DB::table('ceshi')->orderBy('id','desc')->get();
//分页
// $data = DB::table('ceshi')->limit(1)->offset(1)->get();
$dats = [
'name' => 'fengyunshan',
'age' => '123',
'gender' => '1',
];
$res = DB::table('ceshi')->where('age','=','123')->get();
dump($res);
}
public function view()
{
$date=[
'name' => 'fengyunshan',
'age' => '123',
'gender' => '1',
];
//return view('admin.user.view',['date' => $date]);
return view('admin.user.view',compact('date'));
// $User = new User();
// $User->get();
}
public function addmodel(Request $request)
{
User::create($request->all());
return 'chenggong';
}
public function froms(Request $request)
{
return view('admin.user.froms');
}
public function yanzheng(Request $request)
{
$this->validate($request,[
'name' =>'required|min:2|max:10',
'age' =>'required|numeric',
'gender' =>'required',
],[
'name.required' => '名字不能为空',
'name.min' => '名字最少2个字符',
'name.max' => '名字最多10个字符',
'age.required' => '年龄不能为空',]);
User::create($request->all());
return 'chenggong';
}
/*
* php arstisan make:controller创建控制器
* php arstisan make:model 创建模型
* php arstison make:mirgration 创建迁移文件
* php arstison make:seeder 创建迁移文件种子
*
* php arstison migrate 迁移文件
* php arstison migrate:install 执行迁移文件
* php arstison migrate:rollback 回滚迁移文件
*
* php arstison db:send --class=name 发送数据到数据库
*
* php arstison serve 启动服务
*
* php arstison toute:list 显示路由列表
* Session:put('key','value') Session中存入一个值
* Session:get('key') Session中取一个值
* Session:has('key') 判断一个值是否存在
* Session:forget('key') 删除一个值
* Session:flush() 清空所有值
*
* Cache 缓存
* Cache::get('xxx','默认值') 获取缓存
* Cache::has('xxx') 判断缓存是否存在
* Cache::forget('xxx') 删除缓存
* Cache::flush() 清空所有缓存
* Cache::remember('xxx',$min,function(){}) 缓存并获取
* Cache::rememberForever('xxx',function(){}) 缓存永久
* Cache::add('key','value',$min) 存入缓存
* 联表查询
* DB::table('table as t1')->select('要查询的字段')->leftjoin('table as t2','t1.id = t2.user_id')->get()
*
* 模型的关联方法一对一
* public function rel_user(){
* return $this->hasOne('被关联模型的路径','被关联模型的外键','当前模型的外键')
* }
* 使用
* public function text(){
* $data = User::all()
* foreach($data as $key=>$value){
* $value->rel_user->username
* }
* }
* 模型关联方法一对多
* public function rel_pinglun(){
* return $this->hasMany('被关联模型的表','被关联模型表的外键','当前模型的外键')
* }
* 使用
* public function text(){
* $data==User::all()
* foreach($data as $key=>$value){
* $value->id;
* foreach($value as $k=>$v){
* $v->comments;
* }
* }
* }
*
*/
public function fromsr(Request $request)
{
$data=artion::all();
foreach($data as $key=>$value){
echo $value->wenzhang;
echo '
';
foreach($value as $k=>$v){
echo $v->keyword;
}
}
}
}
Route::get('/', function () {
return view('welcome');
});
Route::get('/home/{id}', function ($id) {
return $id;
});
Route::get('text2','admin\UserController@index');
Route::get('add','admin\UserController@add');
Route::get('del','admin\UserController@del');
Route::get('sel','admin\UserController@sel');
Route::get('get','admin\UserController@get');
Route::get('view','admin\UserController@view');
Route::any('addmodel','admin\UserController@addmodel');
Route::get('froms','admin\UserController@froms');
Route::post('yanzheng','admin\UserController@yanzheng');
Route::get('fromsr','admin\UserController@fromsr');
Title
这是视图文件
{{$date['name']}}
@foreach($date as $k=>$v)
{{$k}}:{{$v}}
@endforeach
@if($date['age']>18)
大于18
@else
小于18
@endif
@extends('admin.user.parent')
@section('content')
这是子视图
@endsection
@show
@include('admin.user.parent')
//php artisan serve