severity: Warning
Message: Creating default object from empty value
Filename: controllers/person.php
line Number: 133
function update($id)
{
$responce = new StdClass;
$this->_set_rules();
$person = $this->Person_model->get_by_id($id)->row();
error in this line i try to figure it ot
$this->form_data->id = $id;
$this->form_data->name = $person->name;
$this->form_data->gender = strtoupper($person->gender);
$this->form_data->dob = date('d-m-Y',strtotime($person->dob));
$data['title'] = 'Update person';
$data['message'] = '';
$data['action'] = site_url('person/updatePerson');
$data['link_back'] = anchor('person/index/','Back to list of persons',array('class'=>'back'));
// load view
$this->load->view('personEdit', $data);
}
Lowercase "s" in stdClass:
$response = new stdClass;
NOT:
$responce = new StdClass;
Find out more on PHP objects here:
http://php.net/manual/de/language.types.object.php
You need to create the data object as shown below.
$responce = new stdClass();
Hope this will solve your error.
Related
I am trying to upload multiple images but unfortunately, I am getting an error "message": "The file "phpzP428U.png" does not exist", How can I solve this? Thanks.
return request
dd($request->all())
InboxController
foreach ($request["file"] as $key => $value) {
$file = Storage::disk('yourstitchart')->putFile('', $value);
array_push($files, $file);
}
foreach ($request["users"] as $key => $users) {
$digitzingInbox = new Inbox;
$digitzingInbox->file = json_encode($request[$files]);
$digitzingInbox->order_id = $request->order_id;
$digitzingInbox->order_name = $request->order_name;
$digitzingInbox->width = $request->width;
$digitzingInbox->height = $request->height;
$digitzingInbox->placement = $request->placement;
$digitzingInbox->format = $request->format;
$digitzingInbox->fabric = $request->fabric;
$digitzingInbox->instruction = $request->instruction;
$digitzingInbox->to_user = $users;
$digitzingInbox->from_user = Auth::user()->id;
$digitzingInbox->type = 2;
$digitzingInbox->save();
}
I think its self explanatory, that file may not exist in folder. Look it up the name if it matches.
I am creating a group and also storing users id's in it but its showing error in foreach loop i.e. Invalid argument supplied for foreach().
Here is my controller code :
public function createGroup(Request $request)
{
$user_id = request('user_id');
$member = request('member');
$data = array(
'name'=>$request->name,
);
$group = Group::create($data);
if($group->id)
{
$resultarr = array();
foreach($member as $data){
$resultarr[] = $data['id'];
}
$addmem = new GroupUser();
$addmem->implode(',', $resultarr);
$addmem->group_id = $group->id;
$addmem->status = 0;
$addmem->save();
return $this->sendSuccessResponse([
'message'=>ResponseMessage::statusResponses(ResponseMessage::_STATUS_GROUP_SUCCESS)
]);
}
}
I am adding values like this,
Desired Output,
I just want that each member to store with different id's in table and group id will be same.
Please help me out
Avoid that if check, it does absolute nothing.
if($group->id)
Secondly your input is clearly a string, explode it and you will have the expected results. Secondly don't save it to a temporary variable, create a new GroupUser immediately.
foreach(explode(',', $member) as $data){
$addmem = new GroupUser();
$addmem->user_id = $data;
$addmem->group_id = $group->id;
$addmem->status = 0;
$addmem->save();
}
That implode line makes no sense at all, i assumed there is a user_id on the GroupUser relation.
u need to send array from postman
like
Key | value
member[] | 6
member[] | 3
or
$memberArray = explode(",", $member = request('member'))
if($group->id)
{
$resultarr = array();
foreach($memberArray as $data){
$resultarr[] = $data['id'];
}
$addmem = new GroupUser();
$addmem->implode(',', $resultarr);
$addmem->group_id = $group->id;
$addmem->status = 0;
$addmem->save();
return $this->sendSuccessResponse([
'message'=>ResponseMessage::statusResponses(ResponseMessage::_STATUS_GROUP_SUCCESS)
]);
}
I am trying to update the setting but unfortunately, I am facing an error on how to fix this error? please help me thanks.
please see error https://flareapp.io/share/yPaYdGP4
Controller
public function settingupdate(Request $request)
{
$input = $request->except('_token','logo_image');
if ($request->logo_image) {
$setting = Settings::where('key','logo_image')->first();
$input['logo_image'] = $request->logo_image;
$input['logo_image'] = Storage::disk('cms')->putFile('', $request->file('logo_image'));
$request->file('logo_image');
}
foreach($input as $key => $value) {
$setting = Settings::where('key',$key)->first();
$setting->value = $value;
$setting->save();
}
return back()->with('success', 'Setting Successfully updated')- >with('path',$setting);
}
You are getting error because of below line. This line returning no record and you are setting value on it $setting->value = $value
$setting = Settings::where('key',$key)->first();
To resolve this you can check whether data exist or not
$setting = Settings::where('key',$key)->first();
if ($setting !== null) { // add this
$setting->value = $value;
$setting->save();
}
I have upload form which user can add posts with tags. When I enter tag in the input field I've got this error
FatalThrowableError in BelongsToMany.php line 866:
Type error: Argument 1 passed to Illuminate\Database\Eloquent\Relations\BelongsToMany::formatSyncList() must be of the type array, null given, called in
This is what I have in Tag model
public function itemTags()
{
return $this->belongsToMany('App\Item', 'item_tag');
}
In my Item model
public function taggs()
{
return $this->belongsToMany('App\Tag', 'item_tag');
}
The field in my view
<div class="form-group">
{!! Form::label('inputTags', 'Tags', array('class'=> 'col-sm-2 control-label')) !!}
{!! Form::text('tags', null, ['class'=>'form-control', 'id'=>'inputTags']) !!}
</div>
And the controller
public function store( ItemRequest $request )
{
$image = $request->file('image');
$filename=null;
if( $image && $image->isValid()){
$extension = $image->getClientOriginalExtension();
$uploadPath = public_path(). '/uploads';
$filename = rand(111,999). '.'. $extension;
$image->move($uploadPath, $filename);
}
$item = new Item;
$item->title = $request['title'];
$item->category_id = $request['category_id'];
$item->description = $request['description'];
$item->user_id = Auth::user()->id;
$item->url = $request['url'];
$item->image = $filename;
if($item->save()){
if(!is_null($filename)) {
$item_image = new Item_Images;
$item_image->image = $filename;
$item_image->item_id = $item->id;
$item_image->published = 1;
$item_image->save();
}
$request->session()->flash('alert-success','Item added successfully.');
}else
$request->session()->flash('alert-error','Can not add item now. Plese tyr again!!.');
$item->taggs()->sync($request->tags);
return redirect()->route('frontend.user.myitems');
}
The error is on this line
$item->taggs()->sync($request->tags);
What is the problem here?
Maybe your request of tag value $request->tags get empty, Try to call sync like:
$syncTagData = array();
//Passing empty array if tag request is empty...
if(!empty($request->tags)){
$syncTagData= $request->tags;
}
$item->taggs()->sync($syncTagData);
Update
If your request $request->tags not the type array, try below code:
$syncTagData = array();
//Passing empty array if tag request is empty...
if(!empty($request->tags)){
array_push($syncTagData, $request->tags);
}
Today I got same error in many to many relationship between a plot and features.
Reason behind this was user wasn't selecting the features and null was passing to sync()
$plot->featureset()->sync($request->features);
Solution:
$feature_set = ($request->features) != null) ? $request->features : [];
$plot->featureset()->sync($feature_set);
Regards
Try this it works for my project.
if (isset($request->tags)) {
$intern->tags()->sync($request->input('tags'), false);
} else {
$intern->tags()->sync(array());
}
I'm wonder how can I get custom attribute,
My custom attribute call "tim_color"
I was try get by $_product->getAttributeText('tim_color');
after execute I get fatal error Call to a member function getAttributeText() on a non-object
when I'm used
$data['color'] = $product->getTim_color();
in the result i'm get id, but I need the name of atrribute, how can I resolve this problem
My code of script:
$mage_csv = new Varien_File_Csv(); //mage CSV
$products_model = Mage::getModel('catalog/product')->getCollection();; //get products model
$products_model ->addAttributeToSelect('*');
$products_row = array();
foreach ($products_model as $prod)
{
#print_r($prod);
$product = Mage::getModel('catalog/product')->load($prod->getId());
$data = array();
$data['id_product'] = $product->getId();
$data['color'] = $product->getTim_color();
$data['sku'] = $product->getSku();
$data['name'] = strip_tags($product->getName());
$data['description'] = trim(preg_replace('/\s+/', ' ', strip_tags($product->getDescription())));
$data['price'] = $product->getPrice();
$products_row[] = $data;
}
thx for help
Try,
$_product->getData(’tim_color’);
I hope you can get the attribute value by getAttributeText() also. Check out,
$_product = Mage::getModel('catalog/product')->load($item->getId()); //getting product
$_product->getAttributeText('tim_color'); //getting custom attribute value
Detailed discussions are here and here.