Support the ongoing development of Laravel.io →
Eloquent Forms
Last updated 1 year ago.
0

Probably because your query doesn't return a result so the $products variable is not an object.

Also one time you are using $request->product_name and one time $request->name_product.

Also you are selecting the product based on the name and after that check in the code if the name is the same you just selected.

Also at the top you use $request->product_name and a little lower you use $request->get('product_name').

0

Thanks friend, but not fix, when update get succes but for create new I get this error, and I changed the name, regards.

 $products=Product::where('product_name','=',$request->product_name)->first();
   $a=$products->product_name;
   $b=$request->product_name;
   $id=$products->id;
   $compare=$a==$b;
   $exists=$products->quantity;
   $enter=$request->quantity;
   $sum=$exists + $enter;
   
   if ($compare) {
$upproduct=Product::find($id);
$upproduct->quantity = $sum;
$upproduct->save();
return redirect('product')->with('message', 'update');
   
    }
    else
    {
        $product=Product::create([
    'product_name'=>$request->get('product_name'),
    'quantity'=>$request->get('quantity')
    ]);
return redirect('product')->with('message','store');
    }
0

I make dd to $a=$products->name_product;

this result when product exists, dd($a=$products->product_name);

if no existes get object non-property.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

njuarezgt njuarezgt Joined 2 Oct 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.