Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
I have used join that joins to two tables that has the same id column name, while passing it to the view and how to access the ids of both tables.
You can use SELECT as:
$example = Example::join('example2', 'example2.id, '=', 'example.id')
->select([
'example.id AS id',
'example2.id AS id2'
])
->where('')
->get();
view:
foreach($example as $result)
{
$id = $result->id;
$id2 = $result->id2;
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to use Laravel isDirty() which helps me to get only modified values,
But there is a problem when I'm trying to use, it always return false
public function update(Request $request, $id) {
$client = Client::find($id);
dd($client->isDirty('name'));
}
It always return false.
It returns false because you haven't done anything to $client.
Thus, it is not "dirty" - it is "clean".
If you do something like $client->name = str_random(40); it'll become dirty.
To get only modified attributes, you need to use the getDirty() method. isDirty() only shows if there are any modified attributes:
$client = Client::find($id);
$client->name = 'Some New Name';
$modifiedAttributes = $client->getDirty();
If you want to check if any of properties were modified in the submitted form or not, you can do it like this:
if ($client->name === $request->name)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
There is one quiz excel sheet which has 3000 questions.which has question_no, options, test_name, category, question_text,correct_answer,tags fields. using "Spreadsheet" gem i have parsed data from excel.
Now I have one hash which stores "tags type" as key and tag related questions are stored in an array as value.
if questions_hash[tags_string] == nil
questions_hash[tags_string] = []
questions_hash[tags_string].push question
which look like this,
tags = {"tag1" => [value],"tag2" => [value] }
and other hash is,
categories = {"cat1" => "", "cat2" => "" }
and i want to assign tags hash as a value in categories hash.like
categories = {"cat1" => {"tag1" => [value], "tag2" => [value]} ,"cat2" => {"tag3" =>[value] }}
how can i do this?
Hash does has push method.
To insert value into Hash use simple assignment as:
questions_hash[tags_string] = question
Similarly, if you want to insert questions_hash as value to catetory hash use:
hash['History'] = questions_hash
That's it.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have response like this how to parse this data ? any suggestions
{"response":[{"job_id":"29","message":"egfn","lattitude":"26.9514731","longitude":"89.4524783","job_status":"P","date":"2013-11-21
03:33:34","username":"users"},{"job_id":"28","message":"egfn","lattitude":"26.9514731","longitude":"89.4524783","job_status":"P","date":"2013-11-21
03:33:34","username":"rajeev"},{"job_id":"27","message":"egfn","lattitude":"26.9514731","longitude":"89.4524783","job_status":"P","date":"2013-11-21
03:33:34","username":"pankaj"},{"job_id":"26","message":"test job for
you","lattitude":"25.4558641","longitude":"80.1325838","job_status":"P","date":"2013-11-21
01:09:58","username":"users"},{"job_id":"24","message":"test job for
you","lattitude":"25.4558641","longitude":"80.1325838","job_status":"D","date":"2013-11-21
01:09:58","username":"amit"},{"job_id":"25","message":"test job for
you","lattitude":"25.4558641","longitude":"80.1325838","job_status":"P","date":"2013-11-21
01:09:58","username":"test"}]}
Thanks in advance
You can do this:
JSON.parse('{"response":[{"job_id":"29","message":"egfn","lattitude":"26.9514731","longitude":"89.4524783","job_status":"P","date":"2013-11-21 03:33:34","username":"users"},{"job_id":"28","message":"egfn","lattitude":"26.9514731","longitude":"89.4524783","job_status":"P","date":"2013-11-21 03:33:34","username":"rajeev"},{"job_id":"27","message":"egfn","lattitude":"26.9514731","longitude":"89.4524783","job_status":"P","date":"2013-11-21 03:33:34","username":"pankaj"},{"job_id":"26","message":"test job for you","lattitude":"25.4558641","longitude":"80.1325838","job_status":"P","date":"2013-11-21 01:09:58","username":"users"},{"job_id":"24","message":"test job for you","lattitude":"25.4558641","longitude":"80.1325838","job_status":"D","date":"2013-11-21 01:09:58","username":"amit"},{"job_id":"25","message":"test job for you","lattitude":"25.4558641","longitude":"80.1325838","job_status":"P","date":"2013-11-21 01:09:58","username":"test"}]}')
EDIT:
to get all job_id do this:
var obj = JSON.parse('{"response":[{"job_id":"29","message":"egfn","lattitude":"26.9514731","longitude":"89.4524783","job_status":"P","date":"2013-11-21 03:33:34","username":"users"},{"job_id":"28","message":"egfn","lattitude":"26.9514731","longitude":"89.4524783","job_status":"P","date":"2013-11-21 03:33:34","username":"rajeev"},{"job_id":"27","message":"egfn","lattitude":"26.9514731","longitude":"89.4524783","job_status":"P","date":"2013-11-21 03:33:34","username":"pankaj"},{"job_id":"26","message":"test job for you","lattitude":"25.4558641","longitude":"80.1325838","job_status":"P","date":"2013-11-21 01:09:58","username":"users"},{"job_id":"24","message":"test job for you","lattitude":"25.4558641","longitude":"80.1325838","job_status":"D","date":"2013-11-21 01:09:58","username":"amit"},{"job_id":"25","message":"test job for you","lattitude":"25.4558641","longitude":"80.1325838","job_status":"P","date":"2013-11-21 01:09:58","username":"test"}]}')
var job_id_array = new Array();
for(var i = 0;i< obj.response.length ; i++){
job_id_array.push(obj.response[i].job_id);
}
You can use JQuery.parseJSON()
More details : http://api.jquery.com/jQuery.parseJSON/
If your JSON string would be stored in the json variable, you may do the follwoing (given that the environment supports ECMAScript5):
var o = JSON.parse(json);
var result=[];
o.response.forEach(function(e){
result.push(e.job_id);
});
console.log(result);
which outputs the content of the result array:
["29", "28", "27", "26", "24", "25"]
Here's a live demo and a good answer which addresses your question.