I want to get single value from the flashdata array in the view which is sent from the controller.
controller:
$post=array(
'author_id'=>$this->input->post('author'),
'title'=>$this->input->post('post_title'),
'subtitle'=>$this->input->post('post_subtitle'),
'post'=>$this->input->post('textarea1'),
'image'=>$this->upload->file_name,
);
$this->session->set_flashdata('postdata',$post);
view
<?php var_dump($this->session->flashdata('postdata'))?>
The above gave me the following result.
array(5) { ["author_id"]=> string(1) "6" ["title"]=> string(3) "uyk" ["subtitle"]=> string(26) "Full-Stack Web Development" ["post"]=> string(1) "u" ["image"]=> string(0) "" }
How can I get only single value like title or subtitle?
What about this $this->session->userdata['postdata']['title']
Related
here is my request
{
"formulations": [
{
"formulation_id": null,
"formulation_custom_name": "test",
"meal_time_id": null,
"remark": "demo1"
},
{
"formulation_id": 3,
"formulation_custom_name": "asd",
"meal_time_id": 2,
"remark": "demo"
}
]
}
validation rule
'formulations.*.formulation_id' => 'required_with:formulations.*.formulation_custom_name'
working properly for first object i.e formulation_id is required when formulation_custom_name is present
"errors": {
"formulations.0.formulation_id": [
"The formulations.0.formulation_id field is required when formulations.0.formulation custom name is present."
]
}
now my question is exactly opposite from above scenario i.e validate
formulation_custom_name required when formulation_id is null or not present
like
'formulations.*.formulation_id' => 'required_without:formulations.*.formulation_custom_name'
but this is not working for this request like this
{
"formulations": [
{
"formulation_id": 6,
"formulation_custom_name": "test",
"meal_time_id": null,
"remark": "demo1"
}
}
thanks in advance
required_without rule in Validator checks for field existence/presence and not for empty value or null value.
So you need required_if here, and use like below
'formulations.*.formulation_id' => 'required_if:formulations.*.formulation_custom_name,' // it will work for blank and null
Or if you need more complex condition then you can use requiredIf custom Rule
or if you need vice versa then write like below
'formulations.*.formulation_custom_name' => 'required_without:formulations.*.formulation_id'
Document Link
I'm making a pdf report to download, this is the relevant data. I'm trying to navigate through but I'm having trouble
[
{
"id":1,
"name":"asdfasd",
"description":"fasdfasdfafa",
"user_id":1,
"anonymous":0,
"created_at":"2019-12-09 10:30:50",
"updated_at":"2019-12-09 10:33:25",
"survey_questions":[
{
"id":1,
"question":"asfdasdfsdf",
"user_id":1,
"survey_section_id":1,
"response_type_id":1,
"optional":0,
"num":null,
"rank":null,
"show_text":0,
"created_at":"2019-12-09 10:29:27",
"updated_at":"2019-12-09 10:29:27",
"pivot":{
"survey_id":1,
"survey_question_id":1
}
}
],
"answer":[
],
"evaluation":{
"id":1,
"survey_id":1,
"init_date":"2019-12-04 00:00:00",
"end_date":"2019-12-07 00:00:00",
"report_date":"2019-12-08 00:00:00",
"created_at":"2019-12-09 10:30:50",
"updated_at":"2019-12-09 10:33:25",
"evaluation_results":[
]
}
}
]
It's called $survey, I've tried doing a couple things
$survey->name; //works
$survey->survey_questions; //no result when there should be
$survey->evaluation; //works while the survey_questions doesn't
I would like to access the other stuff like survey_questions, answer and in turn access the stuff inside there.
When I try this I get the mentioned error Invalid argument supplied for foreach()
#foreach($survey->survey_questions as $question)
{{$question}}
#endforeach
This is how I'm sending the data from the controller
$survey = Survey::with('surveyQuestions', 'answer',
'evaluation', 'evaluation.evaluationResults')
->where('id', $id)->first();
$pdf = App::make('dompdf.wrapper');
$pdf->loadView('pdf.report', ['survey' => $survey]);
return $pdf->stream();
What is the correct way to be able to access this data?
I believe you have surveyQuestions() method define in Survey Model, If so then your foreach should be like
#foreach($survey->surveyQuestions as $question)
{{$question}}
#endforeach
I don't know why your first() is giving you back an array (if all the code is the posted and there is no other pieces), but as you can see, in the JSON the first character is [ and so the last is ], so what you are manipulating is an array. Not sure also how $survey->name is working for you, what you should do instead is access the array and than get the value you want:
$survey[0]->name;
#foreach($survey[0]->survey_questions as $question)
{{$question}}
#endforeach
...
You should send array to foreach but you sent json
Try
#foreach(json_decode ($survey->survey_questions,true) as $question)
{{$question}}
#endforeach
I get a problem with the validation of a new user request on my api.
I know there's a problem in my code but I cannot figure it out :
UserType
postUserAction
And I send via google Postman, this json :
{
"username":"Username",
"email":"example#mail.com",
"plainPassword":"SecretPassword",
"lastname":"Smith",
"firstname":"John",
"job_position":"CEO",
"phone":"+666133742",
"company_name":"Microtosh",
"website":"www.omgthatsaflippingspider.com",
"sector":"Food & Stuff",
"address":"12 st Overkill",
"city":"SinCity",
"zip_code":"W4224",
"country":"US",
"billing_infos_same_as_company":true,
"putf":"1",
"das":"Manchester United"
}
Now I seems to validate but I get an error :
Column 'password' cannot be null
When I look up the $form -- before $userManager->updateUser($user) -- I get this :
plainPassword:
{
-children:
{
-first:
{
-errors:
[
"fos_user.password.mismatch"
]
}
second: [ ]
}
}
Now first, why does it validate since it didn't find a match between password and confirmation ?
And am I doing the right thing, with the creation of a new user ? I don't understand what I am missing.
Just change the form type of password field to password instead of repeated and it should work ;)
How to properly use the $this->payments->payment_action(); function?
All I get is this:
object(stdClass)#137 (5) {
["type"]=>
string(14) "local_response"
["status"]=>
string(7) "failure"
["response_code"]=>
string(3) "000"
["response_message"]=>
string(32) "The method called does not exist"
["details"]=>
string(27) "No further details provided"
}
As per the question, You are receiving some objects.
For ex: Here i'm just printing the object content. If you ant to store in db, then you can do with $obj.
$obj = $this->payments->payment_action();
echo "Type = ".$obj->type;
echo "Status= ".$obj->status;
echo "Response code= ".$obj->response_code;
echo "Response Message= ".$obj->response_message;
echo "Details= ".$obj->details;
$rep = $em->getRepository('Entities\User');
$user = $rep->findOneBy(array('email'=>'d*****e#s*****o.com'));
print output:
SELECT t0.uid AS uid1, t0.email AS email2, t0.password AS password3, t0.name AS name4, t0.surname AS surname5, t0.matrikel AS matrikel6, t0.status AS status7, t0.registration_time AS registration_time8, t0.gid AS gid9 FROM user t0 WHERE t0.email = ? LIMIT 1 array(1) { [0]=> string(21) "d*****e#s*****o.com" } array(1) { [0]=> string(6) "string" }
I just wanna the entity, not print output. Where can I disable this?
You probably have the Echo SQL Logger enabled. Turn it off.