Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mateog98's avatar

How to concatenate values?

Hi i have an issue while identifying a product, i have three tables Products, Brands, and Models. Im trying to make my $product->name to be the value con concatenate the $product->brand + $product->name. Is that possible?

ProductController:

public function store(Request $request){

    $product = new Product();
   
    
      $product->ptype_id = $request->ptype_id;
      $product->model_id = $request->model_id;
      $product->brand_id = $request->brand_id;
      $product->name = "    "
    
       $product->save();
       Session::flash('success');
       return redirect()->route('products.view');
   }
0 likes
3 replies
Snapey's avatar

you just want to know how to concatenate a string?

use a period between each part

  $product->name = $request->ptype_id . $request->model_id . $request->brand_id;
1 like
SilenceBringer's avatar

@mateog98 firstly - possible mistake?

$product->name to be $product->brand + $product->name

otherwise something like

$product->name = implode(' ', [
	Brand::find($request->brand_id)->name,
	Model::find($request->model_id)->name,
	... // add params you want to concat
]);
1 like

Please or to participate in this conversation.