0

I try to let my users update their ads and after click on update button i will get this error:

ErrorException in AdController.php line 108:
Creating default object from empty value

my AdController line 108 is:

$ad->company_id = Input::get('company_id');

And here is the refer line to that code in my form: as you can see company_id field is not empty and will pass company id number to that field which is the same as store method and works perfectly in there but for update method returns this error, also when I check my page source codes there is correct company id and isn't empty.

{!! Form::model($ads, ['route' => ['company.update', $ads->id], 'method' => "PUT", 'files' => true]) !!}
<input type="hidden" name="company_id" value ="@foreach ($companies as $company){{ $company->id }}@endforeach">

//the rest of the codes

{!! Form::close() !!}

any idea why is that?

djhru
  • 336
  • 6
  • 28
  • @Bhavik cause if i pass only {{ $company->id }} will get `Undefined variable: company` – djhru May 17 '17 at 08:41
  • you dont have `$ad->company_id` this value – Anar Bayramov May 17 '17 at 08:41
  • @Bhavik this is how render in html `` – djhru May 17 '17 at 08:41
  • @Rodrane it is a column in ads table and when i save ads for first time works just fine and save company id who published the ads but for update it's issue somehow! – djhru May 17 '17 at 08:43
  • Possible duplicate of [Creating default object from empty value in PHP?](http://stackoverflow.com/questions/8900701/creating-default-object-from-empty-value-in-php) – apokryfos May 17 '17 at 09:03

2 Answers2

0

Fixed it!

The issue was

$ad = Ad::find($id);

line before line 108 which was

$ads = Ad::find($id);

before

apokryfos
  • 38,771
  • 9
  • 70
  • 114
djhru
  • 336
  • 6
  • 28
0

I think you should try this:

$ad = Ad::where('id',$id)->first();
$ad->company_id = Input::get('company_id');

Hope this work for you!

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57