how can I create a select box which is filled with values from the db?
The view is published with the $groups variable. In my select box i need $groups->id (hidden, only for storing) and $groups->name. This is currently my form.
{!! Form::open(array('route'=>'store.invitation')) !!}
<div class="form-group">
{{Form::label('username', 'Username')}}
{{Form::text('username', '', ['class' => 'form-control', 'placeholder' => 'Enter Username'])}}
{{Form::label('groupname', 'Gruppe')}}
{{Form::select($groups->name) }}
{{ csrf_field() }}
</div>
<div>
{{Form::submit('Submit',['class' => 'btn btn-primary'])}}
<a class="btn btn-default btn-close" href="{{ route('home') }}">Cancel</a>
</div>
{!! Form::close() !!}
Thanks
You should pass an array of the data that you get from the db. Like this:
Form::select('size', array('L' => 'Large', 'S' => 'Small'));
This documentation might be old, but thats how you can create Form::select in blade.
Related
This question already has answers here:
Add icon to Laravelcollective submit button
(3 answers)
Closed 2 years ago.
#can('user-delete')
{!! Form::open(['method' => 'DELETE','route' => ['users.destroy', $user->id],'style'=>'display:inline']) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-default']) !!}
{!! Form::close() !!}
#endcan
I need to display fa icon instead of DELETE text in the button,
<i class="fas fa-trash-alt"></i>
How can I display this fa icon in that button.
I'm using laravel and bootstrap 4.
Use the Form::button instead of Form::submit to achieve this:
{{ Form::button('<i class="fas fa-trash-alt"></i>', ['class' => 'btn btn-default', 'type' => 'submit']) }}
Then you can simply add the type to submit to the button instance.
You can use something like this:
<div class="input-group margin-bottom-sm">
<span class="input-group-addon"><i class="fa fa-trash-alt"></i></span>
{!! Form::button('name if you need', array('class' => 'form-control') ) !!}
</div>
into your Form::button array you can use everything you need such as 'type'=>'submit'
I want make search by parameters. But it shows i have mixing GET and POST methods. (Error message: MethodNotAllowedHttpException
No message). Blade form by default have POST. i changed to GET. Route have GET method. Maybe you can see what i am doing wrong. This is my VIEW:
{!! Form::open([ 'action' => ['HomePageController#index', 'method' => 'get']]) !!}
<div class="container">
<div class="col-xs-2 form-inline">
{!! Form::label('city_id', trans('quickadmin.companies.fields.city').'', ['class' => 'control-label']) !!}
{!! Form::select('city_id', $cities, old('city_id'), ['class' => 'form-control select2') !!}
</div>
<div class="col-xs-3 form-inline">
{!! Form::label('categories', trans('quickadmin.companies.fields.categories').'', ['class' => 'control-label']) !!}
{!! Form::select('categories', $categories, old('categories'), ['class' => 'form-control select2']) !!}
</div>
<div class="col-xs-3 form-inline">
{!! Form::label('search', trans('quickadmin.companies.fields.name').'', ['class' => 'control-label']) !!}
{!! Form::text('search', old('search'), ['class' => 'form-control', 'placeholder' => 'Search']) !!}
</div>
<div class="form-inline">
<div class="col-xs-2">
<button type="submit"
class="btn btn-primary">
Search
</button>
</div>
</div>
</div>
{!! Form::close() !!}
My controller:
public function index( Request $request)
{
$cities = \App\City::get()->pluck('name', 'id')->prepend(trans('quickadmin.qa_please_select'), '');
$categories = \App\Category::get()->pluck('name', 'id')->prepend(trans('quickadmin.qa_please_select'), '');
$name = $request->input('city_id');
$companies = \App\Company::All()->where('city_id', '=', $name);
return view('table', compact('companies', $companies, 'cities', $cities, 'categories', $categories));
My route:
Route::get('/', 'HomePageController#index');
Thank you for your help.
There is a problem in the form open, try it like this :
{!! Form::open([ 'action' => 'HomePageController#index', 'method' => 'get']) !!}
I am trying to use Laravel 5.2 to add questions to an article. Currently I can edit the article, using the edit function in the ArticleController. I want to have a button on the Article edit view, that allows the user to add a question. So when this is clicked, I need it to take the user to /articles/questions/create, but it needs to bring the ID for the article it has just come from with it, so it can be automatically stored in the article_id field in the db table. How would I do this, currently I can store the article ID by manually typing the in a text box on the creation form. Obviously, the aim is for the user to not have to know the ID of the article, and for it to be added automatically.
My Create function so far:
public function create(){
$questions = Question::all();
$users = User::all();
$articles = DB::table('article')->where('id', 'article_id')->get();
return view('articles/questions/create', ['question' => $questions], ['users' => $users], ['article' => $articles]);
}
The form so far:
<h1>Create & Add Question</h1>
{!! Form::open(array('action' => 'QuestionController#store', 'id' => 'createquestion')) !!}
{{ Form::hidden(csrf_token()) }}
<div class="row col-sm-12 col-lg-12">
{!! Form::label('article_id', 'Article ID:') !!}
{!! Form::text('article_id', null, ['class' => 'large-8 columns']) !!}
</div>
<div class="row col-sm-12 col-lg-12">
{!! Form::label('title', 'Question:') !!}
{!! Form::textarea('title', null, ['class' => 'large-8 columns']) !!}
</div>
<div class="row col-sm-12 col-lg-12">
{!! Form::label('require', 'Required?') !!}
{{ Form::radio('require', 1) }} Yes <br>
{{ Form::radio('require', 0) }} No
</div>
<br>
<div class="row large-4 columns">
{!! Form::submit('Add Question', ['class' => 'button']) !!}
</div>
{!! Form::close() !!}
The form does successfully post the the Database, I just need the ID to automatically insert so that the article can reference it to show the question on the article page.
First of all edit the below lines
$articles = DB::table('article')->where('id', 'article_id')->get();
return view('articles/questions/create', ['question' => $questions], ['users' => $users], ['article' => $articles]);
to
$articles = DB::table('article')->where('id', 'article_id')->first();
return view('articles/questions/create', ['question' => $questions, 'users' => $users, 'article' => $articles]);
Now, take a hidden field in the form you posted above
{!! Form::hidden('article_id', $article->id) !!}
and finally access the article id in your store method.
public function store(Request $request){
$article_id = $request->article_id
}
I am attempting to recursively input a quantity of rows into a mysql database. The rows will all have the same product id but an incremental name given by product_id_incremental_number. My form is as follows:
<div class="row">
<div class="col-lg-6">
<h1>Add a new entry to the database</h1>
<p class="lead">Add your entry below:</p>
<hr>
{!! Form::open(array('method'=>'POST', 'route'=>array('inventory.store'))) !!}
<div class="form-group">
{!! Form::label('production_id', 'Production ID', ['class' => 'control-label']) !!}
{!! Form::text('production_id', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('quantity', 'Quantity of chips:', ['class' => 'control-label']) !!}
{!! Form::number('quantity', null, ['class' => 'form-control']) !!}
</div>
{!! Form::submit('Create New Batch Entry', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
</div>
</div>
#stop
My controller is as follows:
public function store()
{
$data = Input::all();
$batch = $data->replicate($data['quantity']);
$batch->save();
}
return Redirect::route('inventory.index')->with('flash_notice', "Batch Created");
}
I know this isn't the full function to add incremental names to each of the items that would be in the batch, I haven't reached that point yet. My problem is that I cannot replicate an array to then insert each replicate of the batch into the database. Any help on this would be greatly appreciated.
TL;DR: It's a similar problem to ordering more than one pizza on an online cart, you just click a counter that increases the number of pizza that are added to the cart database.
Many thanks,
MF
I want Form model binding for multiple objects in laracollective's Form package?
Something as following?
Form::model([$user,$vendors], array('route' => array('user.update', $user->id)))
Where can I request this feature?
I assume you're using Laravel-Collective, Unfortunately you cant do something like that. instead you can try something like this :
UPDATE
you can query all your model in your controller and combine them like this :
$user = User::where('id',$user_id)->get();
$vendor = Vendor::where('user_id',$user_id)->get();
//merge two model
$user = $user->merge($vendor);
// return $user;
return view('admin.users.edit', compact('user'))
->withTitle('Edit user');
and in your form call them like this :
{!! Form::model($user[1], ['route' => ['admin.users.update', $user],'method'=>'PUT']) !!}
#include('admin.users._formEdit')
<div>
{!! Form::submit('Save user', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
_formEdit.blade.php
<div class="form-group">
{!! Form::label('first_name', 'First Name : ') !!}
{!! Form::text('user[first_name]', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('last_name', 'Last Name : ') !!}
{!! Form::text('user[last_name]', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group ">
{!! Form::label('email', 'Email : ') !!}
{!! Form::email('user[email]', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group ">
{!! Form::label('password', 'Password') !!}
{!! Form::password('password', ['class' => 'form-control']) !!}
</div>
<div class="form-group ">
{!! Form::label('vendor_name', 'vendor_name') !!}
{!! Form::text('vendor_name', null,['class' => 'form-control']) !!}
</div>
OR ANOTHER SOLUTION
create relation between model of your User and Vendor (one-to-one or one-to-many) example
User :
public function vendor(){
return $this->hasOne('App\Vendor','user_id');
}
Vendor:
public function user(){
return $this->belongsTo('App\User','user_id);
}
Build your response query like this :
$user = Vendor::with('user')->find($user_id);
and then in your view template :
{!! Form::model($user, ...) !!}
Vendor: {!! Form::text('vendor_name') !!}
User: {{ Form::text('user[username]') }}
{!! Form::close() !!}