Answer the question
In order to leave comments, you need to log in
How to not assign an ID when creating a record in the database?
When creating an entry (the user creates a password, selects a category). How to implement so that you can create a record without a category_id, check the general box and in the database this record becomes without a category_id.
Creation method in controller:
public function store(Request $request) {
$id = Auth::user()->id;
$pass = new Pass();
$pass->title = $request->title;
$pass->category_id = $request->category_id;
$pass->user_id = $id;
$pass->save();
return redirect()->route('home');
}
<div class="form-group">
<input name="title" type="text" class="form-control" required value="{{ $pass->title ?? ''}}">
</div>
<div class="form-group">
<label for="category_id">Категория</label>
<select name="category_id" id="category_id" class="form-control">
@foreach ($categorys as $category)
<option value="{{$category->id}}">{{$category->title}}</option>
@endforeach
</select>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question