logo
down
shadow

JSON response assign to $var then save to db


JSON response assign to $var then save to db

By : dichong song
Date : November 21 2020, 12:01 PM
Does that help Depends what you want to store...
As I understand it, you want to associate uploads with a user? If you just want to store the filename, which may suffice, maybe do this:
code :
// models/User.php
class User extends Eloquent {

    // ...

    public function setFilesAttribute(array $files)
    {
        $this->attributes['files'] = json_encode(array_values($files));
    }

    public function getFilesAttribute($files)
    {
        return $files ? json_decode($files, true) : array();
    }
}

// Your script
$file = Input::file('file');
$fileName = $file->getClientOriginalName();

$file->move(public_path().'/uploads/userfiles', $fileName);
$user = User::find(1); // Find your user
$user->files[] = $fileName; // This may work, not too sure if it will being a magic method and all
$user->files = array_merge($user->files, [$fileName]); // If not, this will work
$user->save();

return Response::json(array('filelink' => '/uploads/userfiles/' . $fileName));
// models/File.php, should have `id`, `user_id`, `file_name`, `created_at`, `updated_at`
class File extends Eloquent {

    protected $table = 'files';

    protected $fillable = ['file_name']; // Add more attributes

    public function user()
    {
        return $this->belongsTo('User');
    }
}

// models/User.php
class User extends Eloquent {

    // ...

    public function files()
    {
        return $this->hasMany('File');
    }
}

// Your script
$file = Input::file('file');
$fileName = $file->getClientOriginalName();

$file->move(public_path().'/uploads/userfiles', $fileName);
$user = User::find(1); // Find your user
$file = new File([
    'file_name' => $fileName,
    // Any other attributes you want, just make sure they're fillable in the file model
]);
$file->save();
$user->files()->attach($file);

return Response::json(array('filelink' => '/uploads/userfiles/' . $fileName));


Share : facebook icon twitter icon
Attempting to parse or assign JSON response: Response is read as [object Object]

Attempting to parse or assign JSON response: Response is read as [object Object]


By : Zach
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Using Flickr API, Javascript/JQuery, and AJAX, I have the follow code: , to Musa,
C# - Get values from JSON response and assign them to variables

C# - Get values from JSON response and assign them to variables


By : Rebecca Kilberg
Date : March 29 2020, 07:55 AM
will help you I am sorry to answer to my own question but I just found the solution and i wanted to post here: You need to add these lines of code after data
code :
var _dataResponse = JToken.Parse(JsonConvert.SerializeObject(data));
var _dataResponseProductID = _dataResponse["ProductID"];
var _dataResponsePrice = _dataResponse["Price"];
Assign JSON data/response (api response) to itemsArray dynamically

Assign JSON data/response (api response) to itemsArray dynamically


By : Felix Zhang
Date : March 29 2020, 07:55 AM
Does that help After a day of struggle and searching all over the places; finally found the solution.
define an empty array and change from const to var to bind the data dynamically at later stage
code :
var someData = () => [{}]

mounted() {
    axios({ method: "GET", "url": "https://localhost:80/api/values" }).then(result => {
                  this.items = () => JSON.parse(result.data);

                }, error => {
                    console.error(error);
                    this.error= error;
                });
    }

Why can't I assign a JSON response to a variable for using later?

Why can't I assign a JSON response to a variable for using later?


By : Mike Railey
Date : March 29 2020, 07:55 AM
help you fix your problem First of all please name an item in a for loop always in singular form to avoid confusion and the error (the name of the loop element variable hides the same name of the array variable).
code :
for (index, recipe) in recipes.enumerated() { ...
print(recipes[index].name)
print(recipe.name)
How to save axios GET response data as json or as same as the arrived response

How to save axios GET response data as json or as same as the arrived response


By : user3729268
Date : March 29 2020, 07:55 AM
it fixes the issue , You forgot a key for the state:
code :
 this.setState({ data: response.data });
  state = {
    data: []
   }
this.state.data.map((el) => {
        return (
          <Table.Row key={el.id}>
            <Table.Cell>{el.id}</Table.Cell>
            <Table.Cell>
              {el.displayName}
            </Table.Cell>
            <Table.Cell>{el.birthDate}</Table.Cell>
            <Table.Cell>{el.gender}</Table.Cell>
          </Table.Row>
        );
      })
Related Posts Related Posts :
  • how to write r.headers from different urls into one json?
  • Parsing JSON concurrently - panic of runtime error (decoding related)
  • How to fix "Subscript out of range" error in XML HTTP Request
  • Splitting nested arrays as separate entities
  • Trying to parse the JSON and create an extracted JSON
  • NiFi JoltTransformJson outputs only first record
  • Dynamic (But known as another key value) JSON Decoding with Swift Decodable
  • How to use map on json response returned by a REST API with ReactJs
  • How to read a file line by line and then output all lines compounded with sth in jq?
  • java.lang.RuntimeException: Failed : HTTP error code : 400 : Bad Request
  • How to check jq result is null or not?
  • CloudFormation - How to use Sub intrinsic function?
  • VBA: Nested JSON Object Structure for UK Bank Holidays - Run Time Errors 13, 438 and 449
  • JasperReports. Using value from parent json in child table
  • Output key value pairs as JSON from T-SQL query
  • Getting key value pairs with linux server
  • Modifying settings.json in vscode to add shell escape flag to pdflatex in latex workshop
  • Unable to render data into grid column using JSON results
  • JSON decode failed
  • How to remove brakets on Json respone
  • How to parse JSON-input
  • JSON syntax for getting personal query ID
  • detecting 400 response without JSON response
  • Newtonsoft deserializing Json incorrectly
  • Getting _jsonparsefailure with valid json in logstash
  • How to send Map as String in POST request in flutter?
  • Difficulty fetching json data from API using Angular
  • Reading JSON data for my select query in SQL Server
  • AWS CloudFormation Template (JSON) to Create EC2 - Unexpected Error
  • How to concat multiple fields to same line with jq
  • Issue sending POST request from Swift
  • Storing JSON in BigQuery
  • How to get the value of a key in a JSON?
  • How to validate JSON input in Go
  • Extracting specific and latest data from http webserver using golang
  • Incorrect type. Expected "object"
  • json_to_record with embedded encoded json in PostgreSQL >= 10
  • Nested json extract from powershell
  • Parsing Json using Golang
  • Type 'number' is not assignable to type 'string'. How to cast number to string
  • kubectl - format the resource quota values in json format
  • Initializing and inserting nested JSON data in Golang?
  • Open JSON files in PhpStorm built-in web server
  • Extract Badge ID from JSON in .gitlab-ci.yml
  • Sharing Json Schema files among projects with versioning
  • Export Json data to an excel file using Angular 4
  • Return an empty array instead of null with golang for json return with gin
  • can Kafka connect value conveter (JSONConverter) can be used to convert GPB?
  • read json and access multiple keys
  • Spark How to get number of Keys changed in two JSONS in Scala?
  • Break JSON in pager "less"
  • How to filter Map in Flutter?
  • Convert hashmap to simple object in Groovy
  • Not extracting json properly using json4s
  • How do I display JSON data in my tableView when objects have the same value?
  • Where I can parse IoT data in Azure so I can afterwards save it to SQL DB
  • How to unmarshal this json string
  • What's wrong with my JSON?
  • JSON parsing problem in BlackBerry
  • GWT: How can I use JsonpRequestBuilder to handle a Json response of a list
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org