How to display the soap xml message before it's send using laravel-soap - laravel

I managed to use laravel-soap to send and receive requests, but for debugging purposes I want to print/echo the exact xml being send and received.
I tried to use
->trace(true);
but that doesn't seem to help.
So how do I print out the actual soap xml message being send and received
Update: This is my code
<?php
namespace App\Http\Controllers;
use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
class IsController extends Controller {
public function demo()
{
// Add a new service to the wrapper
SoapWrapper::add(function ($service) {
$service
->name('Test')
->wsdl('http://link.to.provider/program.asmx?wsdl')
->trace(true);
});
$data = [
'UserName' => 'XXXXXXX',
'Password' => 'XXXXXXX',
];
// Using the added service
SoapWrapper::service('Test', function ($service) use ($data) {
//var_dump($service->getFunctions());
var_dump($service->getLastRequest());
//dd($service->call('Login', [$data]));
//dd($service->getLastResponse());
});
}
}
I already tried replacing
echo htmlentities($service->getLastResponse());
with
dd($service->getLastResponse());
and
var_dump($service->getLastResponse());
The result is the; same the text "NULL"

If you want to echo it out, try this;
echo htmlentities($service->getLastRequest());
And, for the response:
echo htmlentities($service->getLastResponse());

Related

Catch an error while importing huge CSV in queue using laravel excel

I am using ShouldQueue method to have the large CSV into Queue but the errors of validations I am not able to catch them!
public function registerEvents(): array
{
return [
ImportFailed::class => function(ImportFailed $event) {
dd($event); // This I will write into the FILE or send EMAIL but the job runs successfully but validation errors keep empty.
$this->importedBy->notify(new ImportHasFailedNotification);
},
];
}
My code looks like below
public function registerEvents(): array
{
return [
ImportFailed::class => function(ImportFailed $event) {
$filename = public_path('tmp').'/validation_error.txt';
$myfile = fopen($filename, "w");
fwrite($myfile, "domo");
fclose($myfile);
},
];
}
I am in hope that if there is any error validation_error.txt file will have "Demo" inside it.
Also, I have crossed verify by removing ShouldQueue it gives me proper errors for email already exists a kind of.
Please help if you have any ideas! Thanks!

cookie::make does not save the cookie in Laravel 8

Am I missing something? I am pulling my hair to solve this simple use of cookie. My intention is simply to save a variable for each user (I tried session and there were side effect issues). The below code should theorically save the cookie which should be there at the next call of the page, correct? It does not work. What am I missing?
class TestController extends Controller
{
public function show($page) {
echo #Cookie::get('testcookie');
if (Cookie::get('testcookie')) { echo 'cookie exists<br>'; }
else { echo 'cookie does not exist<br>'; }
$cookie = Cookie::make('testcookie','5', 120);
echo $cookie;
return view('tests.'.$page,['page' => $page]);
}
}
I have also modified config/session.php as recommended for use on http://localhost. Should I clean/cache... or similar after that. I am using laravel 8 & FF on OSX.
'secure' => env('SESSION_SECURE_COOKIE', false)
Can someone please tell me what I am doing wrong?
If I try the other way with response...
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
public function show($page, Request $request)
{
echo $request->cookie('name');
if ($request->cookie('name')) { echo 'cookie exists<br>'; } else { echo 'cookie does not exist<br>'; }
$response = new Response('Set Cookie');
$cookie = $response->withCookie(cookie('testcookie','5', 120));
echo $cookie;
return view('tests.'.$page,[
'page' => $page
]);
}
I get an error "Call to undefined method Illuminate\Support\Facades\Response::withCookie() ".
Why is it so complicated and so simple in php?
You must send maked cookie with response.
Cookie::make() just create cookie object on your backed - but, if you not send them to user - he cannot save them.
class TestController extends Controller
{
public function show($page) {
//for debug
if ($cookie = Cookie::get('testcookie')) { dump ($cookie); }
$cookie = Cookie::make('testcookie','5', 120);
return response()
->view('tests.'.$page,['page' => $page])
->withCookie($cookie);
}
}

dd() not working in vue-laravel project axios call.Is it possible to use dump in axios call?

I am using vue with laravel.but my save function not working. So I tried to dump and die the request object but I can't see the request object in the preview. it is blank.
protected function save()
{
$request = Request::all();
dd($request);
$suggestion = new Suggestion();
$suggestion->connection_id = $request['connection_id'];
$suggestion->company_id = $request['company_id'];
$suggestion->module = $request['module'];
$suggestion->description = $request['image'];
$suggestion->save();
return 'success';
}
the axios call is
axios.post('suggestion/save', this.post).then(response => {
this.$swal({
title: 'Success',
text: response.data.message,
type: 'success',
confirmButtonText: 'OK',
});
this.$router.push('/suggestion-list');
})
There are multiple Request classes in Laravel, One thing you can try is the following,
public function controllerFunction()
{
dd(request()->all());
$suggestion = new Suggestion();
$suggestion->connection_id = $request['connection_id'];
$suggestion->company_id = $request['company_id'];
$suggestion->module = $request['module'];
$suggestion->description = $request['description'];
$suggestion->save();
return 'success';
}
So irrespective of your class, the request() function will bring up the appropriate object.
If you get to dump the request then you can confirm that the request is hitting the appropriate controller function, otherwise, the request is going somewhere else. check the network tab in chrome for more details.
Also, make sure you have the appropriate Request class in the use statements.
The correct Request class usage is like following
use Illuminate\Http\Request;
Add request to your function
also add 'use Illuminate\Http\Request'
use Illuminate\Http\Request
public function myFunction(Request $request)
{
dd($request->all());
...
}
hey you can use print() or print_r() to check result
and make sure your this.post has data or not

Api-Platform GET itemOperation to get User by E-Mail or Username

How can I use a custom controller action to get an entity by its second identifier like get User by Email oder Username?
I tried to write the resource.yaml like this:
App\Entity\User:
itemOperations:
get:
method: 'GET'
path: '/users/{id}'
getByEmail:
method: 'GET'
path: '/users/email/{emailaddress}'
controller: 'App\Controller\User\GetByEmailAction'
Is this a possible approach at all or is it only the way to call GET on the collection and use a filter like /users?email=...?
Yes, you can create a custom operation.
namespace App\Controllers;
class GetByEmailAction {
public function __invoke($emailaddress, EntityManagerInterface $em) {
$user = $em->getRepository(User::class)->findOneBy[
'email' => $emailaddress
];
if (!$user) {
throw new NotFoundException('User not found');
}
return $user;
}
}
check the docs for more examples Custom operation

Codeigniter XML-RPC Sample code issue

Trying to run Codeigniter User Guide XML RPC Sample Code.
This is the code
xmlrpc_client.php
<?php
class Xmlrpc_client extends CI_Controller {
function index()
{
$this->load->helper('url');
$server_url = site_url('xmlrpc_server');
$this->load->library('xmlrpc');
$this->xmlrpc->server($server_url, 80);
$this->xmlrpc->method('Greetings');
$request = array('How is it going?');
$this->xmlrpc->request($request);
if ( ! $this->xmlrpc->send_request())
{
echo $this->xmlrpc->display_error();
}
else
{
echo '<pre>';
print_r($this->xmlrpc->display_response());
echo '</pre>';
}
}}?>
xmlrpc_server.php
<?php
class Xmlrpc_server extends CI_Controller {
function index()
{
$this->load->library('xmlrpc');
$this->load->library('xmlrpcs');
$config['functions']['Greetings'] = array('function' => 'Xmlrpc_server.process');
$this->xmlrpcs->initialize($config);
$this->xmlrpcs->serve();
}
function process($request)
{
$parameters = $request->output_parameters();
$response = array(
array(
'you_said' => $parameters['0'],
'i_respond' => 'Not bad at all.'),
'struct');
return $this->xmlrpc->send_response($response);
}}?>
After this, i ran the url like this.
remoteserver's ip/xmlrpc_client
(i deleted my index.php using .htaccess, dont need to type it)
the result is like this,
Did not receive a '200 OK' response from remote server. (HTTP/1.1 404 Not Found)
If i run the server code,
remoteserver's ip/xmlrpc_server
it says like this.
This XML file does not appear to have any style information associated with it. The document tree is shown below.
Which means,
$this->xmlrpc->send_request()
this request have been failed
and echoed
echo $this->xmlrpc->display_error();
Any idea what is the problem is?
Oh, i have another question.
Do i have to install xmlrpc php extension before i use this codeigniter xmlrpc class?
Solved! the problem was the remote sever's firewall.

Resources