Answer the question
In order to leave comments, you need to log in
How to trim the length of a string if the database has a limit on the number of characters?
Hello everyone
In the database there is a limit on the length of 50 characters, and if I try to write 60 characters, there will be an error, but I don’t want to do a crutch in the form of a length of 500 characters for the title. Tell me
how this is decided, in which direction to dig?
All that is:
Standard form
<form action="{{route('admin.category.update', $category)}}" method="post" enctype="multipart/form-data">
<input type="text" class="ss_input" name="title" value="{{$category->title ?? ''}}" placeholder="">
<button class="ss_button">Сохранить</button>
</form>
public function update(Request $request)
{
Categories::where()->where()->update([
//
'title' => $request->title ?? null,
//
]);
return redirect()->route('admin.category.index');
}
Answer the question
In order to leave comments, you need to log in
public function update(Request $request)
{
$request->validate([
'title' => 'max:255', // где 255 - макс. длина строки
]);
// ...
}
maxlength="50"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question