lumen

lumen 添加配置

你。 提交于 2020-04-17 21:20:15
app同级目录新建config目录 添加配置文件 bootstrap/app.php里面加载 $app->configure('options'); 使用 $router->get('/', function () use ($router) { return config('options.author'); }); 来源: oschina 链接: https://my.oschina.net/u/4307541/blog/3270302

lumen中间件 Middleware

霸气de小男生 提交于 2020-04-17 21:17:16
app/http 下新建 TestMiddleware.php <?php namespace App\Http\Middleware; use Closure; class TestMiddleware { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $params = $request->all(); if(empty($params['id'])){ $response = ['code'=>400,'msg'=>'参数错误','data'=>[]]; return response()->json($response); } return $next($request); } } bootstrap/app.php里面启用 $app->routeMiddleware([ //'auth' => App\Http\Middleware\Authenticate::class, 'test'=>App\Http\Middleware\TestMiddleware::class ]);

lumen路由

五迷三道 提交于 2020-04-17 21:12:23
$router-> get ( ' / ' , function () use ($router) { return config( ' options.author ' ); }); $router -> get ( ' /user/{user_id} ' , function($user_id) { return $user_id; }); $router ->group([ ' namespace ' => ' Admin ' , " prefix " => ' admin ' ], function($router) { $router -> get ( ' user/info ' , " UserController@info " ); }); 来源: oschina 链接: https://my.oschina.net/u/4346209/blog/3270307

How to create symlink for storage public folder for Lumen

久未见 提交于 2020-04-16 03:27:05
问题 I have used the following command to create symnlink for storage public folder for my project which I'm doing in Lumen . => php artisan storage:link But I am getting this error in terminal => There are no commands defined in the "storage" namespace. Another query is though I'm able to upload file in storage folder , how I'm able to access, I need some sample code for this. Kindly help. 回答1: I created by this unix command : ln -s sourceforwhich symnlinkfolderpath e.g.: ln -s /data/html

How to create symlink for storage public folder for Lumen

筅森魡賤 提交于 2020-04-16 03:26:30
问题 I have used the following command to create symnlink for storage public folder for my project which I'm doing in Lumen . => php artisan storage:link But I am getting this error in terminal => There are no commands defined in the "storage" namespace. Another query is though I'm able to upload file in storage folder , how I'm able to access, I need some sample code for this. Kindly help. 回答1: I created by this unix command : ln -s sourceforwhich symnlinkfolderpath e.g.: ln -s /data/html

Cross-Reference Array elements bei named index - PHP/Laravel/Lumen

折月煮酒 提交于 2020-03-25 18:21:45
问题 TL;DR: I want to use data from a 1-dimensional array of arbitrary size, created by userinput, and fill its values into the appropriate fields of a 2-dimensional array of arbitrary size, created via query from the Database. I have a webapplication where the user can access the DBs data both in read-mode and write-mode. The DB records accessible to him are determined by the departments he belongs to. The records are organized in a DB structure where a coretable contains data visible to ALL

Cross-Reference Array elements bei named index - PHP/Laravel/Lumen

心不动则不痛 提交于 2020-03-25 18:21:05
问题 TL;DR: I want to use data from a 1-dimensional array of arbitrary size, created by userinput, and fill its values into the appropriate fields of a 2-dimensional array of arbitrary size, created via query from the Database. I have a webapplication where the user can access the DBs data both in read-mode and write-mode. The DB records accessible to him are determined by the departments he belongs to. The records are organized in a DB structure where a coretable contains data visible to ALL

Lumen/Laravel调试API接口利器laravel-debugbar

痴心易碎 提交于 2020-03-22 22:34:47
Laravel、Lumen打印sql每次都要在手动加调试代码挺麻烦的。本文主要介绍另一个调试神器 barryvdh / laravel-debugbar 先讲一下效果。可以调试带页面的接口,也可以调试单纯的json api接口。 图一:请求的接口列表,可以根据一些条件进行过滤。红色划线的部分是我自己修改composer保增加上去的选项,后面一起放出composer仓库链接。 图二、查看异常(就不用到服务器看日志文件了) 图三、打印sql(所有sql一目了然) 还有其他几个面板,就不截图了。 安装步骤: 1、安装composer包 # 原版composer包,请求接口列表没有我图一划线那几个筛选项composer require barryvdh/laravel-debugbar composer require barryvdh/laravel-debugbar --dev //仅开发环境安装 # 我修改的过的composer包composer require evan766/laravel-debugbar composer require evan766/laravel-debugbar --dev //仅开发环境安装 2、注册服务提供者。该composer包同同时支持laravel和lumen,如果是lumen框架使用,注册的服务提供者要换成lumen的服务提供者

laravel、lumen遇到的问题解决

旧街凉风 提交于 2020-03-12 12:19:30
lumen GET获取参数为空的路由设置 比如我想用GET方式访问地址: http://127.0.0.1/user/参数 使用官方的路由文档是: $app->get('user/{id}', function ($id) { return 'User '.$id; }); 但是,如果id没有传值直接访问 http://127.0.0.1/user/ 就会出现404错误 解决办法就是更改路由为: $app->get('user[/{id}]', function ($id) { return 'User '.$id; }); whereHas中关联的表在另一个库的情况 Users::whereHas('posts', function($q) use ($keyword) { if($keyword){ $q->from('postsr的数据库名称.posts')->where('title','like','%'.$keyword.'%'); } }) 队列处理 ##后台运行队列监听 nohup php artisan queue:listen >/dev/null 2>&1 & nohup php artisan queue:work --daemon >/dev/null 2>&1 & //不重新加载整个框架,而是直接 fire 动作 su apache -c -l

PHP开发框架Laravel优点,Laravel5.3中文文档

假装没事ソ 提交于 2020-03-01 06:00:23
PHP开发框架Laravel优点 Laravel的设计思想是很先进的,非常适合应用各种开发模式TDD, DDD和BDD,作为一个框架,它为你准备好了一切,composer是个php的未来,没有composer,PHP肯定要走向没落。 laravel最大的特点和优秀之处就是集合了php比较新的特性,以及各种各样的设计模式,Ioc容器,依赖注入等。因此laravel是一个适合学习的框架,他和其他的框架思想有着极大的不同,这也要求你非常熟练php,基础扎实。 如果你觉得laravel很困难 那么原因只有一个 你php基础不够好。 通常觉得Laravel难学且无用的开发者中,只会PHP一门语言,或者说,没有静态编译型语言(如C/C++/Java/Go等)使用经验的开发者占绝大多数。 路由和orm部分,和前端backbone之类的结合应该很契合,还是很不错的,另外composer是个很好东西,关于效率问题,web程序的运行效率从来就不在框架,而在数据库,框架那一点点消耗根本不会是什么负担。 laravel框架还是蛮不错的,可以说非常全面,配合phpstorm开发还是很好的。 =========================================== PS:Laravel 5.3 在2016年8月24日正式发布了,而且有中文版文档了(有些之前的中文网站还是5.1版本的,没有及时更新