How to Add Some Textfield in Form Register (Laravel Generator Infyom)

How to add some textfield in form register (laravel generator infyom)?

If you want to add some custom field to your registration process because your are using official laravel auth you can add your fields in : /resources/views/auth/register.blade.php

and then you can validate and save your inputs in : /app/Http/Controllers/Auth/RegisterController.php

you don't need to add anything to registeruser in vendor because every thing you add will change and replaced after every composer install or update.

how to get a field from database in the form build in infyom (Laravel)

Laravel Generator package supported to generate CRUD from existing database.

its docs here: https://labs.infyom.com/laravelgenerator/docs/5.8/generator-options#generate-from-table

command:

php artisan infyom:scaffold $MODEL_NAME --fromTable --tableName=$TABLE_NAME

also supported for specific connection (database).

How to install infyOm into laravel?

Check your composer.json file, following should be present in the file:

"require": { 
"infyomlabs/laravel-generator": "dev-master",
"laravelcollective/html": "5.2.*",
"infyomlabs/core-templates": "dev-master"
}

Then run composer update. Problem is with your laravelcollective/html part in your composer.json file.

Laravel login and register forms on the same page in Laravel 5.2

Instead of changing input names, just Override trait function and call it from the overriden function...

With this done, we can store a session value that tell us from where the auth attempt is coming from login or register form!

    use AuthenticatesUsers, RegistersUsers {
AuthenticatesUsers::redirectPath insteadof RegistersUsers;
AuthenticatesUsers::getGuard insteadof RegistersUsers;
login as traitLogin;
register as traitRegister;
}

// Override trait function and call it from the overriden function
public function login(Request $request)
{
//Set session as 'login'
Session::put('last_auth_attempt', 'login');
//The trait is not a class. You can't access its members directly.
return $this->traitLogin($request);
}

public function register(Request $request)
{
//Set session as 'register'
Session::put('last_auth_attempt', 'register');
//The trait is not a class. You can't access its members directly.
return $this->traitRegister($request);
}

and in your View.blade file just check your errors with your Session value ...

<div class="form-group{{ $errors->has('email') && Session::get('last_auth_attempt') == 'login' ? ' has-error' : '' }}">
<label class="col-md-4 control-label">E-Mail</label>

<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">

@if ($errors->has('email') && Session::get('last_auth_attempt') == 'login')
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>

With this you can check if button pressed is from login ou register button

Laravel use same form for create and edit

I like to use form model binding so I can easily populate a form's fields with corresponding value, so I follow this approach (using a user model for example):

@if(isset($user))
{{ Form::model($user, ['route' => ['updateroute', $user->id], 'method' => 'patch']) }}
@else
{{ Form::open(['route' => 'createroute']) }}
@endif

{{ Form::text('fieldname1', Input::old('fieldname1')) }}
{{ Form::text('fieldname2', Input::old('fieldname2')) }}
{{-- More fields... --}}
{{ Form::submit('Save', ['name' => 'submit']) }}
{{ Form::close() }}

So, for example, from a controller, I basically use the same form for creating and updating, like:

// To create a new user
public function create()
{
// Load user/createOrUpdate.blade.php view
return View::make('user.createOrUpdate');
}

// To update an existing user (load to edit)
public function edit($id)
{
$user = User::find($id);
// Load user/createOrUpdate.blade.php view
return View::make('user.createOrUpdate')->with('user', $user);
}


Related Topics



Leave a reply



Submit