Select category for product form Hi guys, I have a Category with id, name and other columns.
I'm creating a form to register a new product and I want the user to select the category he wants the product in.
I was wondering, what is the best way to create a select for the user with the category?
example :
1.category table id , name
2.product table id,category_id,name
than define relationship one(category) to many (product) in laravel and get data as you want.
I know the relationship part, I'm talking about passing the data to the product registration forma where you can select the category you want the product in using a select tag.
@yijani You can store it first then passing it
$data = array(
'id' => $request->get('id'),
'name' => $request->get('name')
);
then passing it
return view('user.yourformblade')->with($data); << just example
then if you want to get it just use {{$id}} or {{$name}} on your form
I don't think you guys understood my question.
It's like this, I have a controller called ProductController and on the create method:
public function create()
{
$categories = Category::get()->pluck('name', 'id');
return view('site.create', compact('categories'));
}
Now I want to put the categories in a select html tag but as I'm using pluck I don't have the $category->name and $category->id.
$categories = Category::select('name', 'id')->get();
Please sign in or create an account to participate in this conversation.