lumen

How to integrate Swagger in Lumen/Laravel for REST API?

大城市里の小女人 提交于 2019-12-04 08:37:34
问题 I have built some REST API in Lumen micro framework and it's working fine. Now I want to integrate Swagger into it so the API will be well documented on future use. Has anyone done this? 回答1: Steps to follow for Laravel Lumen 5.7 with swagger using OpenApi 3.0 specs (this governs the way you write annotations so that swagger documentation is generated) I reached this adjusting on @black-mamba answer in order to make it work. 1. Install swagger-lume dependency (which also installs swagger)

Lumen: Enable CORS

流过昼夜 提交于 2019-12-04 05:49:24
I built an API with Lumen and want to access it with JavaScript and the XMLHttpRequest object. But every time my PUT, GET, POST, and DELETE requests are transformed into OPTIONS - Request . I read a lot of websites with information of CORS. I build middleware with the following content: 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');

Sessions not persisting in Lumen PHP framework

十年热恋 提交于 2019-12-04 04:05:12
I'm using the Lumen (by Laravel) micro-framework for a project, and I'm having some trouble with sessions. I'm just testing the implementation now, but the problem I'm experiencing is that when I set a session variable and then refresh the page, the variable is no longer set. In my .env file I have: SESSION_DRIVER=cookie And I know that this is being picked up, because when I change it to memcached it throws an error (because I don't have memcached set up). I've enabled the middleware too: $app->middleware([ 'Illuminate\Session\Middleware\StartSession', 'Illuminate\View\Middleware

Laravel - Send api_token within the header

你离开我真会死。 提交于 2019-12-03 22:12:16
问题 I'm building an API for Laravel and I want to send the api_token within the header instead of the form post. Is this something that is already built in or would I have to go the route of figuring out how to create my own auth driver? 回答1: After struggling a little with this myself I got it working. You need to first follow this little tutorial on how to use the api_token for your laravel API: https://gistlog.co/JacobBennett/090369fbab0b31130b51 Then once you have the api_token in the users

Lumen: get URL parameter in a Blade view

喜夏-厌秋 提交于 2019-12-03 18:38:24
问题 I'm trying to get a url parameter from a view file. I have this url: http://locahost:8000/example?a=10 and a view file named example.blade.php . From the controller I can get the parameter a with $request->input('a') . Is there a way to get such parameter from the view (without having to pass it from the controller to the view)? 回答1: This works well: {{ app('request')->input('a') }} Where a is the url parameter. See more here: http://blog.netgloo.com/2015/07/17/lumen-getting-current-url

Lumen与Oauth2的整合

a 夏天 提交于 2019-12-03 14:32:54
今天来写一下laravel的分支lumen这个“微框架”,大家看到这个“微”字,总以为是laravel的简化版本,其实不然也。可以去他的官网好好看看。链接地址: https://lumen.laravel.com/docs/5.2/releases 因为最近项目中要用到接口,就用Lumen快速的部署了一下站点。不过Lumen的环境有一定的要求,最好是高版本的, 官方建议是: PHP >= 5.5.9 OpenSSL PHP Extension PDO PHP Extension Mbstring PHP Extension 1、oauth2 既然说到接口,那肯定有授权协议,这里首选是"oauth2"了。这里可以看一下国外一篇文章: http://esbenp.github.io/2015/05/26/lumen-web-api-oauth-2-authentication/ 这里详细的介绍怎么配置,我当初安装他的步骤配置过,可依旧报错, 其中一个是: proxy.php First parameter must either be an object or the name of an existing class 解决方案为: 其中要注意的是在.env 配置选项 AUTH_MODEL=App\Auth\User Lumen默认缓存是memcached,CACHE_DRIVER

Creating custom error page in Lumen

只谈情不闲聊 提交于 2019-12-03 13:13:33
问题 How do I create custom view for errors on Lumen? I tried to create resources/views/errors/404.blade.php , like what we can do in Laravel 5, but it doesn't work. 回答1: Errors are handled within App\Exceptions\Handler . To display a 404 page change the render() method to this: public function render($request, Exception $e) { if($e instanceof NotFoundHttpException){ return response(view('errors.404'), 404); } return parent::render($request, $e); } And add this in the top of the Handler.php file:

Converting a laravel application to lumen

妖精的绣舞 提交于 2019-12-03 12:09:15
So, I have been building a laravel 5.1 API and after months of work on it it dawned on me that I should have been using Lumen all along. Is there a way to convert a laravel app to a lumen app? Lumen is essentially a stripped down version of Laravel. The application structure is the same, so as far as that goes it should be safe to create a new Lumen app and copy the app directory from your Laravel app. However, for performance reasons, Lumen does not have all the Laravel goodies working out of the box, and some are not there at all. So depending on how you've implemented you're Laravel app,

Does task scheduling in Lumen work just like in Laravel?

本秂侑毒 提交于 2019-12-03 11:23:30
You can see task scheduling explained in the latest docs for Laravel, but Lumen's docs do not mention this. However, it looks like Lumen's Console Kernel file has a schedule method just like Laravel. Does scheduling work the same in both, or what are the caveats with scheduling in Lumen? Yes, yes it does! :) It works exactly the same. crontab -e And then add * * * * * php /var/www/domain.com/public_html/artisan schedule:run 1>> /dev/null 2>&1 Come to think of it, the php artisan schedule:run kinda gives it away :p 来源: https://stackoverflow.com/questions/33356416/does-task-scheduling-in-lumen

lumen 响应宏

别等时光非礼了梦想. 提交于 2019-12-03 10:26:31
响应宏 laravel 中的响应宏,说明文档中有,lumen的没有找到。于是参考laravel 项目中的响应宏写了个Lumen的 1. 新建文件 App\Providers\ResponseMacroServiceProvider.php <?php namespace App\Providers; use Laravel\Lumen\Http\ResponseFactory; use Illuminate\Support\ServiceProvider; class ResponseMacroServiceProvider extends ServiceProvider { /** * Bootstrap the application services. * * @return void */ public function boot() { ResponseFactory::macro('success', function ($data) { return ResponseFactory::json([ 'errors' => false, 'data' => $data, ]); }); ResponseFactory::macro('error', function ($message, $status = 400) { return ResponseFactory: