我正在使用Laravel Lumen构建API.
我已经到了需要找出Eloquent生成的SQL查询的地方.我知道如何在Laravel 4和Laravel 5中执行此操作,但我在Lumen中尝试了相同的代码并且查询是空白的?
$queries = DB::getQueryLog();
$last_query = end($queries);
echo 'Query<pre>';
print_r($last_query);
exit;
Run Code Online (Sandbox Code Playgroud)
上面的代码,在Laravel中运行时运行正常 - 在Lumen中,查询是空白的吗?
我使用Lumen构建了一个API,并希望使用JavaScript和XMLHttpRequest对象来访问它.但每次我的PUT,GET,POST和DELETE请求都转换为OPTIONS - Request.我阅读了很多有CORS信息的网站.我使用以下内容构建中间件:
class CORSMiddleware
{
public function handle($request, \Closure $next)
{
$response = null;
/* Preflight handle */
if ($request->isMethod('OPTIONS')) {
$response = new Response();
} else {
$response = $next($request);
}
$response->header('Access-Control-Allow-Methods', 'OPTIONS, HEAD, GET, POST, PUT, DELETE');
$response->header('Access-Control-Allow-Headers', $request->header('Access-Control-Request-Headers'));
$response->header('Access-Control-Allow-Origin', '*');
return $response;
}
}
Run Code Online (Sandbox Code Playgroud)
我的客户代码:
var url = "http://localhost:8000/api/user";
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open('PUT', url, false);
xmlHttpRequest.send('{"username": "ABC", "password": "ABC","email": "mail@cool.xyz" }');
if (xmlHttpRequest.status == 200) {
console.log(xmlHttpRequest.responseText);
}
Run Code Online (Sandbox Code Playgroud)
我的GET请求信息:
Host: localhost:8000
User-Agent: …Run Code Online (Sandbox Code Playgroud) 我在一个项目中使用laravel.在我的本地机器上,我必须访问的服务器就是
laraveltest.dev.当我打开这个URL时,该项目工作正常,没有问题.
但是,当我将它上传到测试服务器上时,其中的东西位于子库中,如下所示:laraveltest.de/test2/.公用文件夹位于laraveltest.de/test2/public/,但在调用laraveltest.de/test2/public应用程序时始终返回404错误.
我认为这可能是因为基本路径,所以我做了以下内容 bootstrap/app.php
$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../') . env('APP_BASE_PATH')
);
Run Code Online (Sandbox Code Playgroud)
env('APP_BASE_PATH')子文件夹在哪里.
所以app->basePath()回报/var/www/laraveltest/test2/public.但是,现在开放的时候
laraveltest.de/test2/public我总是得到404错误,我不知道为什么.我究竟做错了什么?
我有一个大问题.我使用Lumen框架在localhost中处理应用程序.我的工作环境是在Wamp(Windows)上.
Lumen要求root位于public文件夹中.
为此,我有一个像这样的配置文件:
NameVirtualHost name.local
<VirtualHost name.local>
DocumentRoot C:/wamp/www/name/public
ServerName name.local
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
所以,如果我把地址name.local/放在我的浏览器中,我就可以到达索引页面.
现在,我需要将所有工作都放在FTP中.在那里,我有一个异常错误,这是正常的,因为我的根不是public文件夹.
更新:我找到答案,请看下面.
我将此代码放入一个函数(php类)中:
$theFile = '/test/test.xml'; // these are in the public folder
dd(file_get_contents($theFile));
Run Code Online (Sandbox Code Playgroud)
如果我去mydomain.local/test/test.xml,我会得到有效的 xml 代码。
但是file_get_contents,我收到此错误:
file_get_contents(/test/test.xml): failed to open stream: No such file or directory
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
我正在尝试在 Amazon Elastic Beanstalk 中上传 Lumen 项目。
.env 在 .gitignore 中。
这没关系,因为我有几个环境(dev、qa、prod),所以我需要为每个环境配置单独的 env 变量
我收到此错误消息:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Dotenv: Environment file .env not found or not readable. Create file with your environment settings at /var/app/current/bootstrap/../.env' in /var/app/current/vendor/vlucas/phpdotenv/src/Dotenv.php:33 Stack trace: #0 /var/app/current/bootstrap/app.php(4): Dotenv::load('/var/app/curren...') #1 /var/app/current/public/index.php(13): require('/var/app/curren...') #2 {main} thrown in /var/app/current/vendor/vlucas/phpdotenv/src/Dotenv.php on line 33
Run Code Online (Sandbox Code Playgroud)
我知道系统没有找到 .env
事情是我在 Amazon Console 中设置了变量:
Software Configuration
Environment variables: APP_ENV, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_HOST, APP_KEY
Run Code Online (Sandbox Code Playgroud)
eb 打印环境:
Environment Variables:
DB_DATABASE = ebdb …Run Code Online (Sandbox Code Playgroud) amazon-web-services laravel amazon-elastic-beanstalk lumen phpdotenv
目前,我正在开发一项功能,该功能要求应用程序向客户/用户发送电子邮件。
发送电子邮件已经在工作,但是,我希望隐藏/替换发件人的电子邮件。我认为MAIL_FROM_ADDRESS 在.ENV文件正是我需要的,但它并没有给我什么我的预期。
这是我的 .env 文件中的一个片段:
# illuminate/mail
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=steven@gmail.com
MAIL_PASSWORD=PASSWORD_HERE
MAIL_FROM_ADDRESS=admin@MyApp.com
MAIL_FROM_NAME=MyApp
Run Code Online (Sandbox Code Playgroud)
如果用户收到来自我的应用程序的电子邮件,它应该显示“admin@MyApp.com”作为电子邮件的发件人。
+------+
为什么MAIL_FROM_ADDRESS不起作用?
我应该如何使用它?
我认为这是我问题的解决方案是错误的吗?
我应该怎么做才能达到预期的输出?
我期待在流明路由,它似乎并没有被正确地工作,我不能工作,如果它是一个问题,或者我的理解.
$router->get('{adaptor}[/{id}]', ['uses' => 'MyController@readAction']);
Run Code Online (Sandbox Code Playgroud)
这种方式有效,但我更喜欢使用前缀来分组我的所有路由:
$router->group(['prefix' => '{adaptor}'], function () use ($router) {
$router->get('[/{id}]', ['uses' => 'MyController@readAction']);
// CRUD routes to be added here
});
Run Code Online (Sandbox Code Playgroud)
如果我去,/acme我得到MethodNotAllowed异常,但如果我添加/acme/1它工作正常.前缀是否需要另一个路由项才能工作?
我使用这个包https://github.com/zircote/swagger-php来编译 swagger 注释,并且很难创建可重新使用的参数列表。我可以重复使用如下所示的各个参数
/**
* @OA\Get(
* path="/api/v2/seasons/{season_id}",
* description="Show season(s).",
* summary="List season(s) from comma separated id list",
* tags={"seasons"},
* security = { { "basicAuth": {} } },
* @OA\Parameter(
* name="id", in="path",required=true, @OA\Schema(type="integer")
* ),
* @OA\Parameter(ref="#/components/parameters/max-child-depth"),
* @OA\Parameter(ref="#/components/parameters/sort-by"),
* @OA\Parameter(ref="#/components/parameters/sort-order"),
* @OA\Parameter(ref="#/components/parameters/page"),
* @OA\Parameter(ref="#/components/parameters/page-size"),
* @OA\Parameter(ref="#/components/parameters/CatalogHeader"),
* @OA\Parameter(ref="#/components/parameters/SiteHeader"),
* @OA\Parameter(ref="#/components/parameters/AcceptLangHeader"),
* @OA\Parameter(ref="#/components/parameters/DebugHeader"),
* @OA\Response(response=200, ref="#/components/responses/200",
* @OA\JsonContent(type="array", @OA\Items(ref="#/components/schemas/SeasonResponse"))
* ),
* @OA\Response(response=404, ref="#/components/responses/404"),
*
* )
*/
Run Code Online (Sandbox Code Playgroud)
但 id 真正喜欢的是如下所示的内容,因为我可以在每个路由注释定义中重用该标头列表和全局查询字符串参数。
/**
* @OA\Get(
* …Run Code Online (Sandbox Code Playgroud)