Hi,I’m new to idx and laravel,I try to store user details using user.store method,but when button clicked " 127.0.0.1 refused to connect." shows
- users.create
@csrf
First name:
Last name:
<div class="row mt-2">
<div class="col-6">
<label class="col-form-label" for="dob">Date of birth:</label>
</div>
<div class="col-4">
<input type="date" id="dob" name="dob" required>
</div>
</div>
<div class="row mt-2">
<div class="col-6">
<label class=" col-form-label" for="joindate">Join date:</label>
</div>
<div class="col-4">
<input type="date" id="joindate" name="joindate" required>
</div>
</div>
<div class="row mt-2">
<div class="col-6">
<label class=" col-form-label" for="joindate">Hourly rate:</label>
</div>
<div class="col-4">
<input type="text" id="hourlyrate" name="hourlyrate" required>
</div>
</div>
<div>
<button type="submit">Submit</button>
</div>
</form>
- UserController
public function index()
{
//This method will return all users details to UserCard livewire component
$users = User::all();
return View::make(‘users.index’)->with(‘users’, $users);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
return view(users.create);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
$validated = $request->all();
$validated = $validated->validate([
'firstName' => 'required',
'lastName' => 'required',
'dob' => 'required',
'joindate' => 'required',
'hourlyrate' => 'required',
]);
User::create($validated);
return redirect()->route('users.index')
->with('success', 'User created successfully.');
}
- Route
Route::resource(‘users’, UserController::class);