How to add form attribute in laravel - laravel

I know that to insert a attribute in forms in laravel we do something like below
{{ Form::open(array('url' => 'comment', 'method' => 'post')) }}
But what i want to do is insert a attribute like this and not in commas
<form data-abide>
Because I'm using foundation as a front end framework so need to use its validation.

You can add it similar way you add method :
{{ Form::open(array('url' => 'comment', 'method' => 'post', 'data-abide' => 'formclass', 'onSubmit' => 'return false;')) }}

Related

How to send value of a button in laravel collectives?

We can send the values of text as follows in laravel collectives? Is it possible to send the value of a button in laravel collecctives?
{{Form::text('element_id','',['class'=>'form-control'])}}
May the following will do the trick
{{ Form::button('Delete', array('class' => 'btn btn-danger delete', 'type' => 'button', 'value' => 'the value')) }}

Why does not work old in Laravel

I have from:
{{ Form::open(array('url' => 'announcements', 'class' => 'form-inline', 'method' => 'GET')) }}
And checkbox in form:
{{Form::checkbox('only_subscriptions', '1', old('only_subscriptions'))}}
After submit I get empty old():
old('only_subscriptions')
You would use ->withInput() in redirect(), not in view().

Call a controller Action when using route group

I want to call an action of a controller in laravel blade, when using router group...
route
$router->group([
'namespace' => 'Admin',
'middleware' => 'auth',
], function () {
resource('admin/adsense', 'AdsenseController');
resource('admin/post', 'PostController');
});
So, I want call an action of adsenseController in the blade template
{!! Form::model($var, ['method' => 'PATCH','route' => ['what should i write to call an action ']]) !!}
Example (without router groupe)
route
Route::resource('subject','SubjectController');
blade template
{!! Form::model($var, ['method' => 'PATCH','route' => ['subject.actionName']]) !!}
thanks
If you want to use action, try to use this:
'action' => 'SubjectController#index'
Instead of this:
'route' => ['someroute']
https://laravelcollective.com/docs/5.0/html#opening-a-form
So , i want call an action of adsenseController in the blade template
Why don't you simply point your form's action directly to the controller? Eg
{!! Form::model($var, ['method' => 'PATCH', 'action' => 'Controller#method']) !!}
If you want to redirect to a custom route, it's this simple
{!! Form::model($var, ['method' => 'PATCH', 'route' => 'route.name']) !!}
Check out the documentation on Laravel.com

Laravel : I am trying to pass a variable from view to controller but it returns null

This is My View code When i am executing the application it only returns me NULL value, basically my $office_category is not being passed, i need the office category to query the database
<div class="box-body">
{{ Form::open(['route' => 'office.index','class' => 'form-horizontal office-form']) }}
<div class="form-body">
<div class="form-group">
<div class="col-md-3">
{{ Form::select('office_category', [
null=>'Please Select',
'Software' => 'Software',
'Computer Hardware' => 'Computer Hardware',
'Survey Instruments' => 'Survey Instruments',
'Office Equipments' => 'Office Equipments'
], isset($office_category) ? $office_category : '', ['class' => 'form-control input-xlarge select2me', 'placeholder' => 'Project Type', 'id' => 'office_category'] ) }}
</div>
{{ Form::hidden('office_category', $office_category) }}
{{ Form::submit('Search Equipment',['class' => 'btn green']) }}
</div>
</div>
{{ Form::close() }}
My Controller Code: I want the Office category thats it
Class OfficeController extends BaseController{
public function index(){
$office_category = Input::get('office_category');
if($office_category=='')
$offices = Office::orderBy('office_category', 'asc')
->get();
else
$offices = Office::where('office_category','=',$office_category)
->get();
$assets = ['table','datepicker'];
$users = User::where('client_id','=','')
->orderBy('name','asc')
->lists('name','username');
return View::make('office.index',[
'office_category' => $office_category,
'offices' => $offices,
'users' => $users,
'assets' => $assets
]);
}
Where am i going wrong please help.
You have a hidden field directly after your select that has the same name as the select. The value of this hidden field (empty) is what is getting sent to the server.
Delete this line:
{{ Form::hidden('office_category', $office_category) }}
Or rename this hidden field.
By default Form::open creates a POST request and your index method on Controller are expecting a GET request.
You need to add a new route on routes.php to match this POST request.
Route::post('index', 'OfficeController#index');
Or if you don't mind, you can set index to listen any kind of request:
Route::any('index', 'OfficeController#index');
In most of the case, above answer will solve your problem. If not, you can inspect your web request from browser and confirm value in $office_category variable.

laravel using twitter bootstrap and datepicker

I am trying to render a datepicker in the form created by laravel tags. So far, nothing else is showing except a regular text field.
I've used this for the datepicker. And I did the below in the form:
<p>{{ Form::text('dob', '', array('class' => 'form-control','placeholder' => 'تاريخ الميلاد', 'data-datepicker' => 'datepicker')) }}</p>
Nonetheless, I am only getting this:
What is the recommendation here? I also added the css and js to the header so all should be in place.
Thanks,
Update: calling datepicker js function in the footer.blade.php where all other calls are:
{{ HTML::script('/public/assets/js/bootstrap-typeahead.js') }}
{{ HTML::script('/public/assets/js/bootstrap-datepicker.js') }}
<script>
$('.datepicker').datepicker()
</script>
This still didn't change anything.
Use an id to initialize the datepicker
{!! Form::input('date', 'dob', date('d-m-Y'), ['class' => 'form-control', 'id' => 'dob', 'data-date-format' => "dd-mm-yyyy"]) !!}
and use this javascript
$('#dob').datepicker();

Resources