lumen

PHP Lumen Call to a member function connection() on null

大憨熊 提交于 2019-12-12 09:32:57
问题 Call to a member function connection() on null is the error I'm receiving when trying to use an Eloquent Model in Lumen. Controller func: /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { $employees = Employee::orderBy('first_name', 'asc')->get(); dd($employees); $response['precontent'] = view('admin::employee.search')->render(); $response['content'] = view('admin::employee.index') ->with(['employees' => $employees]) -

Laravel - Collection with relations take a lot of time

╄→尐↘猪︶ㄣ 提交于 2019-12-12 09:27:08
问题 We are developing an API with LUMEN. Today we had a confused problem with getting the collection of our "TimeLog"-model. We just wanted to get all time logs with additional informationen from the board model and task model. In one row of time log we had a board_id and a task_id. It is a 1:1 relation on both. This was our first code for getting the whole data. This took a lot of time and sometimes we got a timeout: BillingController.php public function byYear() { $timeLog = TimeLog::get();

Lumen: Enable CORS

女生的网名这么多〃 提交于 2019-12-12 08:45:52
问题 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(

Http Auth dosen't work with PHP

梦想与她 提交于 2019-12-12 03:33:35
问题 I use the Laravel/Lumen Shield Extension for my Http Authentication, however on my local machine everything is perfect, I had only problems on our server. The problem is after I submit the correct login data the login screen appears again. I tried different login data, different browsers, the login screen appears again and again. The last thing I checked up was to change my .htaccess with: RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] But I got only a 404 ... The Http Auth

Why cookie isn't set in Laravel Lumen

佐手、 提交于 2019-12-11 15:46:46
问题 This question is the following of this question. I have a message in my view who says : This site uses cookie [...] Close . When user click on Close , an ajax request is send to the controller. The function is the following : public function acceptCookie(Request $request) { if ($request->valid == 'accept') { $response = new Response('acceptCookie'); if ($response->withCookie(cookie('acceptCookie', 'accepte', 44000))) { return Response()->json(array('statut' => 'Succes')); } else { return

Return object using with() in Laravel Eloquent

℡╲_俬逩灬. 提交于 2019-12-11 15:22:46
问题 Currently I get data like so: ->with(['posts' => function ($query) { $query->active()->available()->limit(1)->with('user'); }]) and it returns the user data as an array of objects which is expected. Because I am using a limit and will only ever need one result, I'd like to return it as a regular object, so instead of: "data": value, "posts": [ { "data": value, "user": { "data": value } } ] I'd like to return it as: "data": value, "post": { "data": value, "user": { "data": value } } What's the

How to upload multiple files using Lumen Multiple file upload

筅森魡賤 提交于 2019-12-11 14:18:21
问题 This is the code I tried so far. Could any one suggest how to alter this code to upload multiple files ? public function uploadFile(Request $request){ $file = $request->file('image') ; $fileName = time().$request->file('image')->getClientOriginalName(); $destinationPath = $request->input('path') ; return $file->move($destinationPath,$fileName); } 回答1: $file_ary = array(); $file_count = count($request->file('image') ); $a=($request->file('image')); $finalArray=array(); $file_count; for ($i=0;

Unable to set cookie with Laravel Lumen

时光怂恿深爱的人放手 提交于 2019-12-11 12:57:38
问题 According to the documentation, I am trying to create a simple cookie, but this don't work. I create it by using the following code : $response = new Illuminate\Http\Response('Hello World'); $response->withCookie(cookie('name', 'value', 43920)); // 43920 = 1 month When I'm trying to see it in the view, I get this error message : Fatal error: Class 'App\Http\Controllers\Illuminate\Http\Response' not found in [...]\app\Http\Controllers\nameController.php How to solve this problem ? 回答1:

Properly inject AuthManager?

橙三吉。 提交于 2019-12-11 12:24:01
问题 I am using jwt-auth library, which injects AuthManager using type-hinting: use Illuminate\Auth\AuthManager; class Basic extends Authorization { public function __construct(AuthManager $auth, $identifier = 'email') { $this->auth = $auth; $this->identifier = $identifier; } The problem is that if I used the middleware jwt.auth: app('Dingo\Api\Routing\Router')->version('v1', ['middleware' => ['jwt.auth'] , 'prefix' => 'api', 'providers' => ['jwt']], function ($api) { $api->get('protected',

Lumen custom authentication without Eloquent

最后都变了- 提交于 2019-12-11 10:14:21
问题 After posting a question Lumen + Dingo + JWT is not instantiable while building about Lumen and Dingo here in SO I got a nice detailed answer on how to set up such a system. Within his setup there is a small authentication example, which uses Eloquent. Now we are loading an custom framework within Lumen, which has its own models etc, and has its own database connection etc. What I can not seen to figure out is how to completely remove Eloquent, and do the authentication using our own