I new to Laravel and newer to Twilio.
I have a working laravel 5.4 server installed w/ Composer. I installed the Twilio SDK in the root directory of my Twilio project w/ Composer.
I receive the following error when loading some basic code from the "Getting Started with Twilio and the Laravel framework for PHP" tutorial.
Class 'Services_Twilio_Twiml' not found
I really don't know what to do now.
Does anyone have any suggestions?
Route::match(array('GET', 'POST'), '/incoming', function()
{
$twiml = new Services_Twilio_Twiml();
$twiml->say('Hello - your app just answered the phone.
Neat, eh?', array('voice' => 'alice'));
$response = Response::make($twiml, 200);
$response->header('Content-Type', 'text/xml');
return $response;
});
Twilio developer evangelist here.
I think you're trying to call the old version of the Twilio PHP library there.
To use TwiML with version 5 of the PHP library you would use the Twilio\Twiml object, like this:
Route::match(array('GET', 'POST'), '/incoming', function()
{
$twiml = new Twilio\Twiml;
$twiml->say('Hello - your app just answered the phone.
Neat, eh?', array('voice' => 'alice'));
$response = Response::make($twiml, 200);
$response->header('Content-Type', 'text/xml');
return $response;
});
There are a bunch of Twilio and Laravel tutorials available here that might help you too.
Let me know if that helps at all.
Related
I am trying to make an session in my phalcon project, version 4.0 but I am getting this error while creating an session.
Class 'Phalcon\Session\Adapter\Files' not found
$di->setShared('session',function(){
$session = new \Phalcon\Session\Adapter\Files();
$session->start();
return $session;
});
If someone knows a method in which I can create an session please let me know!
this seemed to work for me
$di->setShared('session',function(){
$session = new Phalcon\Session\Manager();
$files = new Phalcon\Session\Adapter\Stream( [
'savePath' => '/tmp',
]);
$session->setAdapter($files)->start();
return $session;
});
Phalcon\Session\Adapter\Files class was renamed to Phalcon\Session\Adapter\Stream in Phalcon 4.0.0
check the documentation for other issues you could run into if you recently upgraded
if you copied that code from the documentation then its for Phalcon 3.4.x
I am currently creating Rest API for Android Team using Laravel 5.2 and testing the API in RESTCLIENT.
I am just trying to get the form values which are entered in Restclient with POST method.
I have problem with POST method.. I m just not able to get the form field values. My API for GET method works fine.
Kindly guide me.
Thanks
This is how you handle POST request in laravel. Be it 5.2 or 5.4.
Route::post('books', 'BookController#store');
Controller
pubic function store(Request $request)
{
$name = $request->name;
$name = $request->get('name');
$name = request('name'); //global helper
//Your testing with api so you should return to api if you want to see it
return response()->json($name);
}
Then check in Android console if you receive $name in JSON format.
For SEO purposes I'd like to include the locale of my Laravel project pages in the url, such as http://localhost/en or http://localhost/nl/about.
In trying to achieve this I have found a few tutorials and packages, but I'm not entirely happy with them. The most popular suggestion is mcamara's laravel-localization package, but creating URLs requires a very long function call. Other packages are either for older Laravel versions or offer a lot of functionality I don't need, which would only clutter my code and database.
Marwelln's tutorial seems perfect: it modifies URLs the way I want, works with the default URL helpers like action(), url() and route() and doesn't create unnecessary database tables. However, this tutorial seem to be for Laravel 5.0 and not compatible with Laravel 5.4. Could anyone help me to achieve such URL modification in the newest Laravel version in the most basic way?
Try the following:
In your RouteServiceProvider.php add these lines at the beginnig of the map() method:
$locale = $request->segment(1);
if($locale) {
$this->app->setLocale($locale);
$this->prefix = $locale;
}
And the mapWebRoutes() method should look like this:
protected function mapWebRoutes()
{
$parameters = [
'middleware' => 'web',
'namespace' => $this->namespace,
];
if ($this->prefix) {
$parameters['prefix'] = $this->prefix;
}
Route::group($parameters, function ($router) {
require base_path('routes/web.php');
});
}
Then follow the rest of the instructions in the link of the example you provide. I guess that should be all.
NOTE: the line $this->app->setLocale($locale) has not much sense since you are doing that on the middleware.
I am using the repo https://github.com/mschwarzmueller/laravel-ng2-vue/tree/03-vue-frontend so I have 100% confidence in the reliability of the code. I can post through the laravel api endpoint through the very simple Vue client, and also through Postman. Through Postman I can retrieve the table data array, but not so in the client app. In POSTMAN:
localhost:8000/api/quotes
works just fine.
IN THE vue 2 js CLIENT APP:
methods: {
onGetQuotes() {
axios.get('http://localhost:8000/api/quotes')
.then(
response => {
this.quotes = (response.data.quotes);
}
)
.catch(
error => console.log(error)
);
}
returns nothing. returning the response to Console.log returns nothing. The Network/XHR tab shows the table data rows, but I am not sure what that means.
I know for sure that this code works for others with their unique api endpoints, which I assume may not use localhost or '127:0.0.1:1080.
Edit: in response to request for more info
public function getQuotes()
{
$quotes = Quote::all();
$response = [$quotes];
return response()->json($response, 200);
}
and the relevant route:
Route::get('/quotes', [
'uses' => 'QuoteController#getQuotes'
]);
Just to confirm: I am using verified github repo code in which the ONLY change is my api endpoint addressas mentioned in the first line of the body of this question. . Note that the Laravel back end is also derived from a related repo in Max's fine tutorial. The running code can be seen at
So I really don't think this is a coding error- but is it a configuration error due to me using local host??
EDIT: It WAS a coding error in the laravel controller as shown below
The reason your code isn't working if because you haven't provided a key for your $quotes in your controller but you're looking for it in your vue file (response.data.quotes).
[$quotes] is essentially [0 => $quotes] so when the json response comes through it be 0: [...] not quotes: [...].
To get this to work you just need to change:
$response = [$quotes];
to:
$response = ['quotes' => $quotes];
Furthermore, just an FYI, you don't need to provide the 200 in response->json() as it's the default and you can just return an array and Laravel automatically return the correct json response e.g.:
public function getQuotes()
{
$quotes = \App\Models\Artist::all();
return compact('quotes'); //<-- This is just another way of writting ['quotes' => $quotes]
}
Obviously, you don't have to if you don't want to.
Hope this helps!
I am using codeigniter and would like to implement omnipay. My development environment is windows and i use wamp server. After much struggle i installed it downloading composer and then curl and then changing the access controls in httpd.conf.
Now i am having trouble using the functions of omnipay. I have created a gateway with this code
echo 'testing the omnipay';
require 'Vendor/autoload.php';
use Omnipay\Common\GatewayFactory;
$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('some_username');
$gateway->setPassword('some_password');
$gateway->setSignature('some_signature');
$gateway->setTestMode(true);
I am not sure how to proceed furthur
I would like to know if there are any tutorials or online documentation for proper use of omnipay
regards,
Nandakumar
Once you have set created the gateway, you can make a purchase with it. The documentation is in the README which comes with Omnipay.
There is an example here: https://github.com/omnipay/omnipay#tldr
and here: https://github.com/omnipay/omnipay#gateway-methods
$response = $gateway->purchase(['amount' => '10.00', 'currency' => 'USD', 'card' => $formData])->send();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
$response->redirect();
} else {
// payment failed: display message to customer
echo $response->getMessage();
}