MVC全名是Model View Controller,是模型-视图-控制器的缩写
Model是html' target='_blank'>应用程序中用于处理应用程序数据逻辑的部分
View是应用程序中处理数据显示的部分
Controller是应用程序中处理用户交互的部分
app包含了用户的核心代码
booststrap包含框架启动和配置加载文件
config包含所有的配置文件
database包含数据库填充与迁移文件
public包含项目入口可静态资源文件
resource包含视图与原始的资源文件
stroage包含编译后的模板文件以及基于文件的session和文件缓存、日志和框架文件
tests单元测试文件
wendor包含compose的依赖文件
3.路由多请求路由Route::match([ get , post ]), match , funtion() return match Route::any([ get , post ]), funtion() return any });路由参数
Route::get( user/{name} , funtion($name) return $id;})- where( name , [A-Za-z]+ Route::get( user/{id}/{name?} , funtion($id, $name= phyxiao ) return $id. $name;})- where([ id = [0-9]+ , name = [A-Za-z]+路由别名
Route::get( user/home , [ as = home , funtion() return route( home }]);路由群组
Route::group([ prefix = user ], funtion() Route::get( home , funtion() return home Route::get( about , funtion() return about });路由输出视图
Route::get( index , funtion() return view( welcome });4.控制器创建控制器
php artisan make:controller UserControllerphp artisan make:controller UserController --plain路由关联控制器
Route::get( index , UserController@index5.模型
php artisan make:model User6.数据库
三种方式:DB facode原始查找 、查询构造器 和Eloquent ORM
相关文件 config/database.php、.env
$bool = DB::table( user )- insert([ name = phyxiao , age = 18]);$id = DB::table( user )- insertGetId([ name = phyxiao , age = 18]);$bool = DB::table( user )- insert([ [ name = phyxiao , age = 18], [ name = aoteman , age = 19],var_dump($bool);
$num= DB::table( user )- where( id , 12)- update([ age = 30]);$num= DB::table( user )- increment( age , 3);$num= DB::table( user )- decrement( age , 3);$num= DB::table( user )- where( id , 12)- increment( age , 3);$num= DB::table( user )- where( id , 12)- increment( age , 3, [ name = handsome
$num= DB::table( user )- where( id , 12)- delete();$num= DB::table( user )- where( id , = , 12)- delete();DB::table( user )- truncate();
$users= DB::table( user )- get();$users= DB::table( user )- where( id , = , 12)- get();$users= DB::table( user )- whereRaw( id = ? and age ? , [12, 18])- get();dd(users);$user= DB::table( user )- orderBy( id , desc )- first();$names = DB::table( user )- pluck( name $names = DB::table( user )- lists( name , id $users= DB::table( user )- select( id , age , name )- get();$users= DB::table( user )- chunk(100, function($user){dd($user);if($user- name == phyxiao )return false;});
$num= DB::table( user )- count();$max= DB::table( user )- max( age $min= DB::table( user )- min( age $avg= DB::table( user )- avg( age $sum= DB::table( user )- avg( sumEloquent ORM
// 建立模型// app/user.php ?phpnamespace App;use Illuminate/Database/Eloquent/Model;class User extends Model //指定表名 protected $table = user //指定id protected $primaryKey= id //指定允许批量赋值的字段 protected $fillable= [ name , age //指定不允许批量赋值的字段 protected $guarded= []; //自动维护时间戳 public $timestamps = true; protected function getDateFormat() return time(); protected function asDateTime($val) return val;}
// ORM操作// app/Http/Contollers/userController.phppublic function orm() //all $students = Student::all(); //find $student = Student::find(12); //findOrFail $student = Student::findOrFail(12); // 结合查询构造器 $students = Student::get(); $students = Student::where( id , = , 10 )- orderBy( age , desc )- first(); $num = Student::count();
a herf = {{action( UserController@index )}} text /a a herf = {{route( url )}} text /a @stop
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP !
相关推荐:
laravel的目录结构
以上就是Laravel 学习的基础知识的详细内容,PHP教程
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。
新闻热点
疑难解答