I have a form in my vue.js frontend where i upload multiple images and asynchronously send it to the backend.
But it seems laravel cant understand it as a file because it's more than one.. And it works fine if it was just a single image without multiple attribute attached to the input field.By the way, i used form data to process the form.. Even tried to stringify the array of files and decode it in the backend still doesnt work.. It is processing it as a strings. When i loop through the files and try to use the function getClientOriginalName() (as i would with single upload) i get 'Call to undefined method stdClass::getClientOriginalName()'.. Also figured that the stdClass is an obj of numbers when i checked..
Below is my code.
let product_img_array = this.image_data.map(item => item.file);
let payload = new FormData;
payload.append("all_images", JSON.stringify(product_img_array));
Backend:
foreach (json_decode(request()->all_images) as $key => $value) {
dd($value->getClientOriginalName()); //this returns the error i mentioned above
dd($value);//this returns {#325} as i said earlier.
}
What is it i'm doing wrongly, probably there is a way of doing this and i'm off track. Please your help is appreciated ..
Related
I am trying to render my mailable in the browser in order to check the content. However I'm getting this message {"message":"sha1() expects parameter 1 to be string, object given","status_code":500}
My code snippet
I am running Dingo/Api on my page as well an I think it's somehow connected with it.
Can you please give me the suggestion why am I getting this message instead of rendering mailable?
Thank you
We got this to work by assigning the mailable to a var first and then directly calling the render function on it, like so:
$mailable = new YourMailableName();
return $mailable->render();
I have the following code (please excuse the bad coding, it's like that to debug):
$postData = Mage::app()->getRequest()->getPost();
if(!$postData)
{
$postData = $this->getRequest()->getPost();
}
if(!$postData)
{
$postData = $_POST;
}
As you can see, I am simply trying to get the HTTP POST values.
Here's the scenario:
From a HTTP POST Simulator, the data comes through
From the Shopify webhook, nothing comes through (just "Array()")
Shopify posting to PostCatcher shows a lot of data
Shopify is posting in JSON format.
Any ideas as to ahy I can't catch the POST array?
You cant get JSON post values by using simply $_POST or Mage::app()->getRequest()->getPost();. Just try this,
$value = json_decode(file_get_contents('php://input'));
print_r($value);
In one of my project I got the same error
Mage::app()->getRequest()->getPost(); was giving the blank values.
I was using one extension when I was submitting the form there was one description field for the manufacturer.
If it was having text content like from , select or some content similar to SQL commands.
It was not posting the form data.
The reason was the hosting provider had some settings for sanitizing the data to prevent the SQL injection.
I raised the ticket to the hosting provider and the problem was solved.
Before this I tried lot of coding stuff which was not required.
Basically
Mage::app()->getRequest()->getPost(); and $this->getRequest()->getPost(); are the same if you are in a controller.
They are also the same thing with $_POST with some additional filtering on the values.
So if you receive an empty array in any case you should receive an empty array for all cases.
Make sure the data is sent through POST.
Also try to see how $this->getRequest()->getParams() look like. Maybe Magento considers that the parameters are sent through _GET
I am struggling to understand something that I am sure one of you will be able to easily explain. I am somewhat new to MVC so please bear with me.
I have created a controller that handles all of the work involved with connecting to the Twitter API and processing the returned JSON into HTML.
Route::get('/about', 'TwitterController#getTweets');
I then use:
return View::make('templates.about', array('twitter_html' => $twitter_html ))
Within my controller to pass the generated HTML to my view and everything works well.
My issue is that I have multiple pages that I use to display a different Twitter user's tweets on each page. What I would like to do is pass my controller an array of values (twitter handles) which it would then use in the API call. What I do not want to have to do is have a different Controller for each user group. If I set $twitter_user_ids within my Controller I can use that array to pull the tweets, but I want to set the array and pass it into the Controller somehow. I would think there would be something like
Route::get('/about', 'TwitterController#getTweets('twitter_id')');
But that last doesn't work.
I believe that my issue is related to variable scope somehow, but I could be way off.
Am I going down the wrong track here? How do I pass my Controllers different sets of data to produce different results?
EDIT - More Info
Markus suggested using Route Parameters, but I'm not sure that will work with what I am going for. Here is my specific use case.
I have an about page that will pull my tweets from Twitters API and display them on the page.
I also have a "Tweets" page that will pull the most recent tweets from several developers accounts and display them.
In both cases I have $twitter_user_ids = array() with different values in the array.
The controller that I have built takes that array of usernames and accesses the API and generates HTML which is passed to my view.
Because I am working with an array (the second of which is a large array), I don't think that Route Parameters will work.
Thanks again for the help. I couldn't do it without you all!
First of all, here's a quick tip:
Instead of
return View::make('templates.about', array('twitter_html' => $twitter_html ))
...use
return View::make('templates.about', compact('twitter_html'))
This creates the $twitter_html automatically for you. Check it out in the PHP Manual.
Now to your problem:
You did the route part wrong. Try:
Route::get('/about/{twitter_id}', 'TwitterController#getTweets');
This passes the twitter_id param to your getTweets function.
Check out the Laravel Docs: http://laravel.com/docs/routing#route-parameters
NOTE: This question is related to CodeIgniter-RestServer
When I call model.save() from backbone the function where the put request is routed doesn't gets any PUT data. Firebug shows right PUT parameters being sent. However $this->put('keyname') always returns false. Which means CI's REST Server can't find PUT data as it should.
On the other hand, If I set:
Backbone.emulateJSON = true;
I can work, as then Backbone will send all PUT data under a single attribute named "model", using this way $this->put('model'); works
Then the extra effor involved is:
$data = json_decode($this->put('model'),true); // to get normal behavior #sucks
I was running into this issue as well and pushed a few changes that fix the problem:
https://github.com/philsturgeon/codeigniter-restserver/pull/84
have been through this problem already in the past. Solution to this problem is to use this inside your functions:
$data = $this->request->body;
echo $data['id'];
Hope that solves it. Cheers!
I have a variety of functions within my models which serve a different purpose.
One for example looks up the data for a given $_GET variable in the URL string.
I am trying to work out a way of displaying an error message if there is no matching row in the database due to url string manipulation for example.
My first idea was simply to return an error message (if there is an error) with each call to the function, then simply have an if statement whereby if there is an error, an error view is shown, and if not the normal view is shown..
Problem with this is that this function is called numerous times in my controller, and other similar functions are called throughout my code which need similar error handling..
I dont want millions of similar if/else statements all over my code to handle errors..
Anyone got any better ideas?
Cheers
Use the flashdata item of the session class. You can concatenate error messages and put them in the flashdata item to display.
my_function(){
// code that determines if there is an error returns => $error
if ($error)
{
// concat previous and current errors
$new_error = $this->session->flashdata('errors') . $error;
// replace 'errors' with newly concatenated errors
$this->session->set_flashdata('errors', $new_error);
}
}
This will keep track of all errors generated through each request and allow you to display a "list" of errors for that particular request.
echo $this->session->flashdata('errors');