I want to pass the selected user id to controller from select box.How can I achieve it?
{!! route('approve', ['id' => $user->id]) !!}
In select box,
{{ Form::select('Actions', [
'approve' => 'Approve',
'decline' => 'Decline']
) }}
My resulto to be like this,
First of all you'll need an input for selecting users. For example I got a list of users with their username and id here :
$users= \App\Users::pluck('username','id');
after sending it to the view, you can use an input for selecting user :
{!! Form::select('user_id', $users,'0', ['class' => 'form-control']) !!}
That's it. Now you can select the user and get data as $_POST['user_id'] or $_GET['user_id'] in the action. gl.
Related
I am trying to make a form to update deadline where I need to edit the date and time. Also I want the form to have a calendar. I want to add the default value with calendar option
I am having the deadline as this format n database 2019-04-25 00:00:00
Here is the code I made to add the calendar:
View with the calendar
{{ Form::label('Abstracts Submission Deadline', 'Abstracts Deadline') }}
{{ Form::input('dateTime-local','Abstracts', $rss->Abstract_Submission_Deadline, ['class' => 'form-control', 'placeholder' =>$rss->Abstract_Submission_Deadline ]) }}
View without the calendar
{{ Form::label('Ranking Deadline', 'Ranking Deadline') }}
{{ Form::text('Ranking', $rss->Ranking_Deadline, ['class' => 'form-control', 'placeholder' => $rss->Ranking_Deadline ] ) }} `
The first box I have the calendar without the default value, the second one I have the default value without the calendar
Use value attribute instead of placeholder.
I am trying to show the name of the company but it is a related Model
A company has Stocks
A Stock belongs to a Company
I have tried this:
$userStocks = \Auth::user()->stocks->pluck('type', 'id')->toArray();
{!! Form::select('name', $userStocks, null, ['class' => 'form-control', 'placeholder' => 'Pick Your Stock']) !!}
But I don't know how can I get the name of the company which owns that stock?
Load the data and create an array for the Form::select() manually by using the map() helper. Something like:
$stocks = Stock::where('user_id', auth()->user()->id)
->with('company')
->get()
->map(function($i) {
return [$i->id => $i->type.' - '.$i->company->name];
});
I use dropdownlist from laravelcollective. I am wondering how I can use (Selected Default) with this if I fetch data from a database. Here follows my source code:
{!! Form::select('port',$ports,null,['class'=>'form-control']) !!}
The selected default that I want is for example (Select Port).
First of all create a list in your controller and use as a first element the "Please select a port" text with empty value:
$ports =['' => 'Please Select a port'] + Port::lists('shortName','id')->toArray();
After you pass it to the view use it like this:
{!! Form::select('port_id',$ports,null,['class' => 'form-control']) !!}
The correct is to use attribute placeholder in dropdown.
{!! Form::select('port', $ports, null, ['placeholder' => 'Select a Port', 'class'=>'form-control']) !!}
sorry guys if this is nothing to you all but I seem not to get it I have a drop down and would love to populate it from the database I am using laravel 5.2 and looked at almost all questions asked on this topic and most of it is on laravel 4. I tried populating my combo from database but kept on getting the same error "ErrorException in 0fe8e1e2379436fb1f6f8c15a481341a7cff00e0.php line 22:
Undefined variable: callsign " here is how I have done it form the controller l inserted this code:
$callsign = \DB::table('drivers')->lists('Code');
return view('spotCheck.create')->with('drivers', $callsign);
from my view here is the code:
{!! Form::label('Code','Select a Driver') !!}
{!! Form::select('Code', $callsign, null, ['class' => 'form-control']) !!}
the question is what I am i not doing write and whats up with the error how does my controller know where to populate drop down
for the controller I had to do this
$drive = DB::table('drivers')->lists('Code');
return view('mypage',compact('drive'));
and on the view did this
{!! Form::label ('Call Sign:',null, ['class'=>"control-label"])!!}
{!! Form::select('call_sign', $drive, null, ['class' => 'form-control' , 'id' => 'sel']) !!}
I have a column with datatype of date which is date mutated. I date mutated it so that Laravel will convert it to a Carbon instance and I can use it easily at other places, where I need to convert it into Carbon instance. I am using Model binding in the edit form. As the field is date mutated, on the edit form it appears as "2015-07-29 00:00:00". I need it to be in this format instead: "2015-07-29".
I can't use accessor, as I need it as a Carbon instance at many other places.
I can't explicitly pass value after converting, as I am using the input inside a form partial and I also use it for create.
My workaround is the following:
I am sending a flag while including the view partial in the edit page and using it a condition to have two different code for create and edit.
#if (isset($edit))
{!! Form::text('eta', $order->eta->format('Y-m-d'), ['class' => 'form-control', 'required']) !!}
#else
{!! Form::text('eta', null, ['class' => 'form-control', 'required']) !!}
#endif
Is there a better way?
I think you can avoid from #if and $edit as,
{!! Form::text('eta', ( $order->eta ? $order->eta->format('Y-m-d') : null ) , ['class' => 'form-control', 'required']) !!}