I want to create a ref link like this in laravel 5.4Registration form emails example.com For every registered user and when the link is click it should redirect to the registration form where the ref value is automatically get into the REF form field as given in the image. Here are the related images RegistrationController
Edit : Updated the link generation based on comments
Generate the referral link using the logged in user's email. Assuming you have the logged in user as $user
, if not replace it with auth()->user()->email
. Note that this will need logged in user's email. So it goes without saying that you need to be logged in before to generate the ref link.
If you pass the currently logged in user to your view from controller then do this, where $user = auth()->user();
<a href="{{ route('register', ['ref' => $user->email]) }}" target="_blank">Referral register link</a>
If you want to directly access the logged in user's email
<a href="{{ route('register', ['ref' => auth()->user()->email]) }}" target="_blank">Referral register link</a>
This is how it would look like in the view.
<a href="http://example.com/register?ref=example@example.com" target="_blank">Referral register link</a>
Add the following code in your registration form depending on how you create the form.
<input type="text" name="referrer" value="{{ request('ref') }}">
Or
{!! Form::text('referrer', request('ref')) !!}
The idea like this: In the email make a link like this:
<a href="{{ route('register', ['ref' => auth()->user()->email]) }}">Register</a>
In your form, you can add hidden or disabled textbox like this:
<input type="textbox" name="ref" value="{{ request()->get('ref') }}"/>
You could also add it to the session object in your controller like this:
function create(Request $request) {
return view('register')->with(['ref' => $request->query('ref')]);
}
And populate your form with {!! Former::populate(['ref' => $ref]) !!}
if you're using Former or use form model binding (see here)
Example form markup in register.blade.php with Former:
{!!Former::horizontal_open()
->method('POST') !!}
{!! Former::populate(['ref' => $ref]) !!}
{!! Former::text('ref') !!}
...
{!! Former::actions()
->large_primary_submit('Create') # Combine Bootstrap directives like "lg and btn-primary"
->large_inverse_reset('Reset') !!}
{!!Former::close() !!}