Support the ongoing development of Laravel.io →
posted 10 years ago
Forms

Using Laravel 4.2

I have two tables: Users, Access

Table Users: id name usename password access_ID

Table Access: id access_level description

I want to create a form / view where I have a select box retrieving data from the access table to populate the access level in the select box.

This is my form:

<h1>Create User</h1>

{{ Form::open(array('route' => 'user.store')) }} <ul> <li> {{ Form::label('username', 'Username:') }} {{ Form::text('username') }} </li>

    <li>
        {{ Form::label('password', 'Password:') }}
        {{ Form::password('password') }}
    </li>

    <li>
        {{ Form::label('password', 'Confirm Password:') }}
        {{ Form::password('password_confirmation') }}
    </li>        
    <li>
        {{ Form::label('password', 'Password:') }}
        {{ Form::password('password') }}
    </li>
    <li>

...

....

How do I query the access table to create the select box? And where? the controller? the model? sorry it's an easy question but I don't know the "proper" way to do this in Laravel. Any help appreciated.

Last updated 2 years ago.
0

In your controller

   $user = new User;
   $user->name = 'value_from_form';
   $user->password= 'value_from_form';
   $user->checkbox= 'selected_value_from_form';
   $user->save();

And in blade add your select boxes with the values Form::checkbox('name', 'value');

Last updated 10 years ago.
0

I don't think I understand what you're doing here very well...

you're creating an object User and saving it but it's all hard coded in the controller.

The field

$user->checkbox= 'selected_value_from_form';

I understand, the question I'm asking is how do I show a select box in my view that retrieves data from a "SELECT * FROM access"

and create a SELECT box with fields from the Access table in the "Create new User View"

I don't know if I'm making myself clear...

0

In routes.php

Route::get('/', function(){

	$items = DB::table('Access')->get();
	return View::make('Your_View')->with('items',$items);
});

in your View

    @foreach($items as $item )
        {{ Form::label('the access level ', $item->access_level) }}
        {{ Form::checkbox('access', $item->id ) }}
    @endforeach    
Last updated 10 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ezequiels ezequiels Joined 20 Jan 2015

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.

© 2025 Laravel.io - All rights reserved.