I have a form which stores News.
Here I am using Multiselect and I want to save all the selected option in the table as say Users,staff,cinemahall as a string.
My controller function to store values is
public function store(Request $request)
Make sure you set the name attribute to an array
<select multiple="multiple" name="news" id="news">
To store it as string separated by commas
$news = $request->input('news'); $news = implode(',', $news);
You have a string which will look like
Users,staff,cinemahall. Now, instead to retrieve all input, you may need to retrieve it one by one, since you need to mutate the
news value. Additionally, you can also use
except() method to exclude
news from mass getting all value.
$news = $request->input('news'); $news = implode(',', $news); $input = $request->except('news'); //Assign the "mutated" news value to $input $input['news'] = $news; General_news::create($input); return redirect()->back();