Pass filtered data to Datatables v8 on Laravel v5.6 - elasticsearch

I have an integration with laravel datatables with elasticsearch. For the previous versions, this code was solving the issue.
return value(new CollectionEngine(collect($data), new DatatablesRequest()))
->setTotalRecords($total)
->make‌​(true);
Right now with the new version of datatables (v8) the constructor for collectionEngine has changed and no longer receives a second parameter with the request and the Yajra\DataTables\Request class has be removed as well
Still looking for a solution but with no success on this. How can I make this integration the same way I was doing it before.

Ok, didn't checked the correctly how the constructor was for the collection engine. This has been changed so it get the app request automatic so no need to be injecting new request to it. Only needs to include ->skipPaging() to the datatable.
$response = value(new CollectionEngine($data))
->skipPaging()
->make()

Related

Laravel is not accepting GET API request without any parameter

I am making APIs in Laravel version 8.x for a third party system. For this, I have created few APIs and all routes are mentioned in routes/api.php
In our system, there are few APIs that can be accessible via GET request, that returns data without any authentication and parameters. Look at the routes below in api.php:
//routes/api.php
Route::group(['namespace' => 'App\Http\Controllers\WebServices'], function() {
Route::get('event_types', 'EventWs#getEventTypes');
Route::get('event_type/{event_type_id}', 'EventWs#getEventTypeById');
});
Look at the both routes above. The route having segment is working fine with GET request, but the route without any segment is not calling. This is just a simple GET request without any segment or query string.
I am working on Laravel from past few months, but this issue is strange to me. May be there could be some kind of middleware that prevent GET (without segment or query string) route execution. But I am not able to find reason or that unknown barrier.
Have anyone idea about why this happening or I am missing something?
Please Note that I am using Laravel 8.x

auth() is not working in controller when coming from vue

I have a store method in a controller. now for a field, I am inserting auth()->user()->id. when I am submitting the form from a normal blade, it works fine. but when I am submitting the form from a vue component, it is returning 500 error when I am using auth()->user()->id. instead of this, if i write just 4 or 10 or any static data, it is working fine again!
Maybe the id you submit is in an invalid format and your backend script fails on it. Try to see first if you really have the id and not null or undefined. If so, then see if the id is int or string in your js and then finally see what datatype your backend accepts. If this does not work, please provide some code. You can also see your apache log, what error it throws when you try to access your endpoint.

Session return null anyway

My project is using three different services and now I never can get sessions values, I've tried the laravel site tutorial and fallowing link question :
Laravel - Session returns null
But none of them worked!
In the first, i used this library:
use Session;
In a controller class :
$result = SocketHelper::sendRequest($req);
Session::put('uuid', $result->uuid);
Session::save();
Session::put('userId', $result->userID);
return Redirect::route('login_step_two');
In an other method :
$uuid = Session::get('uuid');
$userId = Session::get('userId');
But these are null! does I have to use cookie?
I recently upgrade to laravel 5.4
Please help me! It's made me confused!
Thanks.
Try saving Session explicitly like this, give it a try it worked for me, hope same for you.
Session::put('test_session', 'test message');
Session::save();
And retrieve it like this
echo Session::get('test_session');
And forget it like this:
Session::forget('test_session');
Session::save();
I understood the null result was becouse I was posting the value of $request to an other template and it was changed it the way :))) !
so easy to know !
Have you properly upgraded to laravel 5.4?
Laravel Docs
Sessions
Symfony Compatibility
Laravel's session handlers no longer implements Symfony's SessionInterface. Implementing this interface required us to implement extraneous features that were not needed by the framework. Instead, a new Illuminate\Contracts\Session\Session interface has been defined and may be used instead. The following code changes should also be applied:
All calls to the ->set() method should be changed to ->put(). Typically, Laravel applications would never call the set method since it has never been documented within the Laravel documentation. However, it is included here out of caution.
All calls to the ->getToken() method should be changed to ->token().
All calls to the $request->setSession() method should be changed to setLaravelSession().
Do you still have the rights to write session files in php session directory ?
Check the path returned by session_save_path() and check if your php user has the rights to write in it, check also if there is files in the directory and what are their creation date.

PHP Kohana 3.2.2 multipart form $_POST not set on MAC but works on Win

I've just encountered a weird problem. I've recently developed a medium size website using Kohana 3.2.2 + jquery + html + WAMP on Windows 7 platform. And everything seems to be working fine, until someone tries accesing the page from Mac platform. It seems that when sending some data with files in multipart form the global variable $_POST is not set, even though when debugging the data in web browser i'm able to see that DATA IS SET :| it's just not accesable by the controller with any $_POST or request->post(). I'm repeating, everything works perfectly when user is accesing page from Windows platform (tested on few separated clients), but not working when accesing from Mac platforms (tested on few separated clients).
It's killing me...
Example of what im trying to do:
In View:
user puts data into inputs (text and file types). Data is being send by form with enctype = multipart/form-data to controller's action
In controller:
$post = request->post();
if($post['sometextinput'] != '') throws exception of unknown index 'sometextinput'.
That's extremely odd. I use Kohana on a daily basis (I develop on a Mac) and have never had an issue like that. Could you post your controller and the view? I'll plug it into a dummy project and see if I can replicate the issue. If I can I'll do what I can to get it working.
EDIT:
Could it possible be an odd configuration issue?
Just for my own clarification.
You're submitting a form that contains input fields and one or more file uploads.
When viewing it on a Windows machine you can see that the data is set in $_POST or $request->post().
On OSX it's not viewable to the controller via $_POST or $request->post();
In your before method make sure you have "parent::before();". If you are already calling parent::before() try putting it as the first statement in your before() method. If that doesn't work try adding it as the last statement. It's a shot in the dark, but it's worth a try.
If you don't have a before() method then add one and call parent::before();.
I'm not sure if you were just in a hurry to type up your example above but it actually should be:
#$post = request->post(); //wouldn't recommend doing this
if($this->request->post('sometextinput') != '') throws exception of unknown index 'sometextinput'.

Retrieving JSON from an external API with backbone

I'm new to backbone.js and I've read other solutions to similar problems but still can't get my example to work. I have a basic rails api that is returning some JSON from the url below and I am trying to access in through a backbone.js front end. Since they are one different servers I think I need to use a 'jsonp' request. I'm currently doing this by overriding the sync function in my backbone collection.
Api url:
http://guarded-wave-4073.herokuapp.com/api/v1/plans.json
sync: function(method, model, options) {
options.timeout = 10000;
options.dataType = 'jsonp';
options.url = 'http://guarded-wave-4073.herokuapp.com/api/v1/plans.json'
return Backbone.sync(method, model, options);
}
To test this I create a new 'plans' collection in my chrome console using "plans = new Plans()" and then "plans.fetch()" to try and get the JSON.
When I call plans.models afterwards I still have an empty array and the object that returns from plans.fetch() doesn't seem to have any json data included.
Any ideas where I'm going wrong?
I have had the same problem before. You should not have to override your sync method.
Taken from Stackoverflow Answer
"The JSONP technique uses a completely different mechanism for issuing HTTP requests to a server and acting on the response. It requires cooperating code in the client page and on the server. The server must have a URL that responds to HTTP "GET" requests with a block of JSON wrapped in a function call. Thus, you can't just do JSONP transactions to any old server; it must be a server that explicitly provides the functionality."
Are you sure your server abides to the above? Test with another compatible jsonp service (Twitter) to see if you receive results?
Have you tried overriding the fetch method as well?
You should add ?callback=? to your api url in order to enable jsonp

Resources