array:4 [▼
"_token" => "IIZcvyxqKwI7WrQ6YKXEqq6NAszLNIps7UvEjAYZ"
"username" => null
"email" => null
"password" => null
]
Yeah so the form isn't submitting. Got any Javascript preventing it from submitting?
Also, what other routes do you have ? On top of that, I noticed that your 'user' is not capitalised on your routes, wanna make them capitalised please and see if that solves it:
Users\UsersController@store etc
Here are all the routes, with directory capitalized. I haven't touched or created any js:
Route::get( '/', 'base\BaseController@index' )->name('home');
#------------------------------------------------------------------------------------
# Users
#------------------------------------------------------------------------------------
Route::get('/user/login', 'Users\UsersController@login');
Route::get( '/user/register', 'Users\UsersController@create' )->name( 'registerget' );
Route::post( '/user/register', 'Users\UsersController@store' )->name( 'registerpost' );
Alright i see you've given your routes a name. Try that in the action of the form. It's worth a shot.
<form method="POST" action="{{ route('registerpost') }}">
<!-- Add your fields here -->
<input type="submit" value="Register">
</form>
A note: when the form validates, it correctly pass value to create the record in the database. So the problem seems specificaly with invalidation.
For some reason, your latest example IS working !! Thank you so much.
@Jaytee it shouldn't matter if he's using the route helper or not, because his store() method is being called upon submitting the form..
@brakkar Change your form method to GET and post the URL in your browser after you submit the form..
<form method="GET" action="/user/register">
You should get something like
http://localhost/user/register?name=foo&username=bar ...
Edit: I'm thinking maybe it was some cache problem.. should perhaps have tried php artisan view:clear
@SaeedPrez Yeah I know, was just trying other options.
So i'm guessing it's either to do with the method not being uppercase, a button of type submit being used instead of an input or the browser was just being funny?
I researched and even though i found something from 8 years ago, one of them was the browser playing up.
Guys, it's all working now. I restarted the entire computer and local servers. Seems there was something messing up upon form submission with clearing the fields. Sorry I should have done that much much earlier computer is being one since several days.
@SaeedPrez Not sure if you remember but i raised a thread the other day where i was having cache problems with Chrome. That might make sense. I tried Canary and same issue so perhaps it's chrome (if that's what OP is using)
Yes, i'm using chrome also.
can you do this please
<?php
// put this class in your App\Http\Requests folder and make sure the namespace match your namespace
namespace App\Http\Requests;
use App\User;
use Illuminate\Foundation\Http\FormRequest;
class UserCreateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'username' => 'required|min:2',
'email' => 'required|email',
'password' => 'required',
];
}
}
public function store(\App\Http\Requests\UserCreateRequest $request)
{
# Create
$user = $this->create($request->all()))
# Authenticate
//auth()->login($user);
# redirect
return redirect()->home();
}
protected function create(array $data)
{
return User::create([
'name' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']), // always make sure not plain password in your database
]);
}
@Jaytee I use <button type="submit"> myself, and lower/uppercase shouldn't matter either. Only thing I can think of now is cache..
Khaled, thanks a lot for the code. Got it working. What an amazing support group guys.
@SaeedPrez Yeah I copied OP's snippet and it worked for me. So I guess we can say it's Chrome. I'm still having Caching issues, you raised the caching issue and OP said he was using Chrome.......
@Jaytee damn Google, they can search billions of websites in 0.0000001s but can't fix a damn cache issue ☺
Well two good things came out of this issue
@SaeedPrez @khaledSMQ and @brakkar
- Brakkar's issue was resolved
- We all got free XP haha
call validation like this instead
$request->validate([
'name' => 'required'
//..
]);
//...
Here you can see the best example to get or retian old value of input, radio, checkboxes, select box, textarea or other input fields
https://codingdriver.com/retain-old-value-on-validation-error-in-laravel.html
Please or to participate in this conversation.