Support the ongoing development of Laravel.io →
Eloquent Views Forms
Last updated 1 year ago.
0

Maybe this works
replace
$components = Component::lists('name','id');
with
$components = Component::all()->lists('name','id');

Last updated 1 year ago.
0

Thanks, but nope -- that still gets a "Trying to get property of non-object" error when I hit submit. It creates the drop-down list just fine, exactly the same as without interposing the all(). But it doesn't change the essential problem, which is that selecting a value from a drop down list sends a single value, not an object. And I can't figure out the syntax in Blade for the Form::open statement that allows the selected id from the drop-down list to be attached and sent to the controller. There MUST be a way to do this -- it's really a very commonly used technique in web programming. It's incredibly easy to do with old fashioned procedural code. But I'm completely stumped at the moment in trying to figure out how to do this in Laravel. I've posted both here and on Stack Overflow, so far with only a couple of responses, and problem not yet solved. Any other ideas? Thanks again!

Last updated 1 year ago.
0
Solution

I finally figured out the problem, and the solution:

The problem is that the form should (optimally) be sent as POST, and therefore not changed from the default value. BUT then the route has to be registered correctly as POST, and that's what I wasn't doing before. So,

dashboard.blade.php:

{{ Form::model(null, array('route' => array('lookupsociety'))) }}
{{ Form::select('value', $societies) }}

Route:

Route::post('lookupsociety', array('as'=>'lookupsociety', 'uses'=>'SocietiesController@lookupsociety'));

SocietiesController@lookupsociety:

public function lookupsociety()
{
    $id = Input::get('value'); ... // proceed to do whatever is needed with $id value passed from the select list
}

It works perfectly! The key was changing the method in the route to Route::post() instead of Route::get().

I knew it had to be simple -- I simply hadn't stumbled on the solution before :)

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

zocios zocios Joined 28 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.