Answer the question
In order to leave comments, you need to log in
How to take the necessary data that came from the form and enter the data into the model?
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class SettingsController extends Controller
{
public function edit()
{
$user = Auth::user();
return view('settings', ['user'=>$user]);
}
public function store(Request $request)
{
$this->validate($request, [
'age' => 'required|numeric|min:18',
'fio' => 'required|max:120|different:about',
'about' => 'required|max:1000|different:fio',
]);
$post = User::add($request->all());
$request->input('fio');
$request->input('age');
$request->input('about');
$post->save();
return redirect()->route('settings');
}
}
<form action="/settings/store" method="POST">
{{ csrf_field() }}
<?php
use Illuminate\Support\MessageBag;
/** @var MessageBag $errors */
?>
<div><input type="text" name="age" placeholder="Укажите возраст" id="age"></div>
<? if($errors->first("age") != "") echo "<div class='alert'>".$errors->first("age")."</div>"; ?>
<div><input type="text" name="fio" placeholder="Укажите ФИО"></div>
<? if($errors->first("fio") != "") echo "<div class='alert'>".$errors->first("fio")."</div>"; ?>
<div><textarea rows="10" cols="45" name="about" placeholder="описание"></textarea></div>
<? if($errors->first("about") != "") echo "<div class='alert'>".$errors->first("about")."</div>"; ?>
<input type="submit" value="Отправить">
</form>
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