Reputation: 1482
I am trying to make a simple authentication application and I have the login/signup form in place and it is working correctly. However, I am having issues with populating the drop-down field for a zip-code from another table. I am not really sure how i should approach this. Most of the time i would just use straight mysql query but I am assuming there is an easier way.
Controller: (would love for the zip_code table to go here.)
public function getSignUp() {
$userdata = array(
'email' => Input::get('email'),
'password' => Hash::make(Input::get('password'))
);
$user = new User($userdata);
$user->save();
return Redirect::to('dashboard');
}
Route
Route::post('signup', 'LoginController@getSignUp');
signup.blade.php
{{ Form::label('email', 'Email:') }}<br />
{{ Form::text('email') }}<br />
{{ Form::label('password', 'Password:') }}<br />
{{ Form::password('password') }}<br />
{{ Form::label('zip_code', 'Zip Code:') }}<br />
{{ Form::select('zip_code', array('zip_code' => '', 'city' => '')); }}<br />
{{ Form::submit() }}<br />
{{ Form::close() }}
This is how I would normally call database information before this
public function showHome()
{
$testimonials = DB::select('SELECT * FROM `testimonials` WHERE `id`=' . mt_rand(1, 2));
return View::make('home.index', array('pageTitle' => 'Home'))->with('testimonials', $testimonials);
}
but with me not returning a view and therefor no variables are going to be passed I am not sure how to achieve this
Any advice would be highly appreciated!
Upvotes: 2
Views: 2397
Reputation: 12460
You can easily list out data from an Eloquent model for a select field using the lists()
function.
Testimonial::lists('content', 'id');
Upvotes: 7