我在我的网络服务器上安装了流明,但我遇到了路由问题
// http://12.345.678.910/
$app->get('/', function() use ($app) {
return "This works";
});
Run Code Online (Sandbox Code Playgroud)
但在第二种情况下,他无法找到目录
// http://12.345.678.910/api
$app->get('/api', function() use ($app) {
return "This dont work";
});
Run Code Online (Sandbox Code Playgroud)
在第二种情况下,我得到标准的404错误.
The requested URL /api was not found on this server.
Run Code Online (Sandbox Code Playgroud)
我使用Apache,Ubuntu,PHP 5.5和Lumen
我正在使用流明试图通过guzzle设置简单的api请求.
问题是base_uri参数似乎没有在初始化时正确传递new Client().
简化示例:
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://siteurl.com/api/v2'
]);
Run Code Online (Sandbox Code Playgroud)
然后通过get调用api
$res = $client->get('orders', [
'query' => [
'status' => 'completed'
]
]);
Run Code Online (Sandbox Code Playgroud)
不起作用.我一直小心不要使用绝对的网址/orders.如果我完全绕过base_uri并将其添加到get方法上$client->get('https://siteurl.com/api/v2/orders'),它就可以工作.
我正在使用:"laravel/lumen-framework":"5.0.*","guzzlehttp/guzzle":"^ 6.0"
*跟进:
我添加了调试标志,以便我可以比较标头,并且明显的区别在于获取请求行.
get方法中的绝对url(绕过base_uri):
GET/api/v2/orders?status =已完成HTTP/1.1
使用base_uri(版本被剥离):
GET/api/orders?status =已完成HTTP/1.1
我是Lumen的新手,想要用这个框架创建一个应用程序.现在我遇到的问题是,如果某个用户输入了错误的网址=> http://www.example.com/abuot(错误)=> http://www.example.com/about(右),我想提出一个自定义错误页面,它将是中间件级别的理想发生.
此外,我能够检查当前url是否有效,但我不确定如何在中间件中"制作"视图,response() - > view()将不起作用.
如果有人可以提供帮助,那会很棒.
我有两个跟随2个模型的多对多关系:
use Illuminate\Database\Eloquent\Model;
class Permission extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'permissions';
/*
|--------------------------------------------------------------------------
| Relationship Methods
|--------------------------------------------------------------------------
*/
/**
* many-to-many relationship method
*
* @return QueryBuilder
*/
public function roles()
{
return $this->belongsToMany('App\Admin\Role');
}
}
Run Code Online (Sandbox Code Playgroud)
和
class Role extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'roles';
/*
|--------------------------------------------------------------------------
| Relationship Methods …Run Code Online (Sandbox Code Playgroud) 我需要构建一个小小部件,并计划使用Lumen,因为我需要快速响应,我需要路由,翻译,请求和视图等组件.现在注意到问题已经在版本5.1之后停止了.
是否可以在更新版本的Lumen中使用视图?
我正在运行一个连接到六个MQ的队列工作器.当它被启动时,它消耗25MB的RAM.即队列中没有任务,即工作人员处于睡眠状态.我在所有项目中使用Larvel,这个特定的项目纯粹是为队列工作者(即没有Web访问的微服务)构建的.
我想减少内存占用,但更重要的是我想知道内存消耗的位置.我正在使用PHP 7.1所以现在xhprof不再是配置文件内存我必须找到一个替代方案.
我知道Lumen意味着消耗更少的内存,至少看起来Lumen是Laravel的一个子集.是否有可能"关闭"我的Laravel应用程序的部分,以便模仿流明?我尝试在config/app.php $providers数组中注释掉行,但内存消耗似乎没有太大的差别(我的测量值约为1MB).
TL;博士; 如何"调整"Laravel内存占用空间?如何将Laravel变成Lumen?
谢谢
编辑:图片或它没有发生.RES列的AFAIK以千字节为单位,因此〜39MB的内存.
尝试在Lumen中手动创建验证器.官方文件写成:
<?php
namespace App\Http\Controllers;
use Validator;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class PostController extends Controller
{
/**
* Store a new blog post.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
if ($validator->fails()) {
return redirect('post/create')
->withErrors($validator)
->withInput();
}
// Store the blog post...
}
}
Run Code Online (Sandbox Code Playgroud)
我写
<?php
namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller as BaseController,
Validator;
class Welcome extends BaseController
{
public function index()
{ …Run Code Online (Sandbox Code Playgroud) 所以,我一直在构建一个laravel 5.1 API,经过几个月的工作,我突然意识到我应该一直使用Lumen.
有没有办法将laravel应用程序转换为流明应用程序?
我正在使用流明5.3.1.$app->withFacades()并且$app->withEloquent()已被取消评论app.php.在web.php我运行以下代码:
$app->get('foo', function () {
return app('db')->select("SELECT * FROM foo");
return "Connected successfully to database " . DB::connection()->getDatabaseName();
});
Run Code Online (Sandbox Code Playgroud)
该select()呼叫正确地从返回的数据foo表.但是,DB::connection()退货:
FatalErrorException in Manager.php line 74:
Call to a member function getConnection() on null
Run Code Online (Sandbox Code Playgroud)
为什么一个工作而另一个工作?
我发现本教程为Laravel安装了一个插件,并由PHPStorm完成了它的方法.
我似乎不适合流明.有没有解决方案目前支持Lumen,因为Lumen是Laravel的一个子集?