I trying to make tooltips into laravelcollective
<div class="form-group col-sm-4">
{!! Form::label('exchange_id', 'Exchanges:') !!}
{!! Form::select('exchange_id', [''=>'Choose Options'] + $exchanges , null, ['class'=>'form-control', 'id'=>'exchange', 'name'=>'exchange_id', 'onchange' => 'all_function()'])!!}
</div>
In the above select box, {!! Form::label('exchange_id', 'Exchanges:') !!} I want to put Bootstrap tooltips like, Exchanges ? : with question mark.
How can I do this?
You can add attribute to label tag, data-toggle="tooltip" and title="Exchanges ?"
<div class="form-group col-sm-4">
{!! Form::label('exchange_id', 'Exchanges:', ['data-toggle' => 'tooltip', 'title' => 'Exchanges ?']) !!}
{!! Form::select('exchange_id', ['' => 'Choose Options'] + $exchanges, null, ['class' => 'form-control', 'id' => 'exchange', 'name' => 'exchange_id', 'onchange' => 'all_function()'])!!}
</div>
Need bootstrap plugin and use like it
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
Tooltips: http://getbootstrap.com/docs/4.1/components/tooltips/
Demo: http://jsfiddle.net/xL1vteoj/
Related
Data is fetching from the database, I want to select all locations coming from the database by default
#php
$default_location = null;
if(count($business_locations) == 1){
$default_location = array_key_first($business_locations->toArray());
}
#endphp
<div class="col-sm-4">
<div class="form-group">
{!! Form::label('product_locations', __('business.business_locations') . ':') !!} #show_tooltip(__('lang_v1.product_location_help'))
{!! Form::select('product_locations[]', $business_locations, $default_location, ['class' => 'form-control select2', 'multiple', 'id' => 'product_locations']); !!}
</div>
</div>
You can select all using jquery.
$(document).ready(function(){
// all selected
$("#product_locations").prop('checked', true);
});
I'm trying to submit a form to a store function. The problem is, the foreignKey (degree_id) keeps being set to ?(null) even though I set it to the id in the route.
Form:
{!! Form::open(['url' => 'degrees/{{ $Degree->id }}', 'method' => 'POST']) !!}
<div class="form-group">
{{Form::label('title', 'Title')}}
<br>
{{Form::text('title', '', ['class' => 'form-control', 'placeholder' => 'Title'])}}
</div>
#error('title')
<small class="text-danger">{{ $message }}</small>
#enderror
Route:
Route::post('degrees/{degree}', 'ModuleController#store');
Store function:
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required',
'desc' => 'required',
'long_desc' => 'required',
'hours' => 'required',
'credits'=> 'required',
]);
$module = new Module;
$module->title = $request->input('title');
$module->desc = $request->input('desc');
$module->long_desc = $request->input('long_desc');
$module->hours = $request->input('hours');
$module->credits = $request->input('credits');
$module->degree_id = $request->route('id');
$module->save();
return redirect('/home/modules');
}
I've since set the degree_id to nullable, so I can create my module and have it display alright, but for future functionality I'd like it to be set to the degree_id. Any idea whats not working here? I do have model-relationships set up, but I can't see how that'd impact it. Maybe something in the route itself?
You can't use Blade Mustache inside a php element, use this instead:
{!! Form::open(['url' => 'degrees/' . $Degree->id , 'method' => 'POST']) !!}
Your route parameter is not named id, you declared it in your route definition as the name degree ('degrees/{degree}').
$request->route('degree');
Change route from
Route::post('degrees/{degree}', 'ModuleController#store');
TO
Route::post('degrees/{id}', 'ModuleController#store');
I could successfully save html/javascript into the database table and it renders it. This is for the first time I have moved to Laravel, YII frameworks automatically caters it but how can I do the same thing in Laravel?
I don't want to use specific checks all over my application, there must be some centralized approach to do so.
Output:
htmlentities($inputs['first_name']); that does the job but how to do this in the whole app. I don't want to have these checks everywhere.
That's how I render form:
{!! Form::model($companyUser, ['route' => ['updateUserProfile', $companyUser->id], 'method' => 'put', 'class' => 'frm-container']) !!}
<div class="col-lg-5">
{!! Form::controlRequired('text', 0, 'first_name', $errors, 'First Name') !!}
</div>
<div class="col-lg-5">
{!! Form::control('text', 0, 'last_name', $errors, 'Last Name') !!}
</div>
<br clear="all"/>
<div class="col-lg-5">
{!! Form::control('password', 0, 'password', $errors, 'New Password') !!}
</div>
<div class="col-lg-5">
{!! Form::control('password', 0, 'password_confirmation', $errors, 'Confirm Password') !!}
</div>
<br clear="all"/>
<div class="col-lg-12 btn-frm-inner">
<button type="submit" class="btn btn-submit">Update</button>
Cancel
</div>
{!! Form::close() !!}
The code you posted is from the form.
You're not supposed to filter what's going in the database in my opinion. You should simply let anything come and then display it the way you want. So this is fine.
Now as for displaying the data :
{{ }} will escape automatically, while {!! !!} will NOT escape anything.
So when you display the data in your view, you should use the first option.
I've created an ActiveForm using yii2 like this:
<?=$form->field($item, 'finalPrice', [
'options' => [
'tag' => 'div',
'class' => '',
],
'template' => '<span class="col-md-2 col-lg-2"><label class="control-label">Final item price</label>{input}{error}</span>'
])->textInput([
// ** i want numeric value **
])->label(false)?>
and it rendered a result of:
<span class="col-md-2 col-lg-2"><label class="control-label">Final item price</label><input type="text" id="item-finalprice" class="form-control" name="Item[finalPrice]"><p class="help-block help-block-error"></p></span>
now i want to make it < input type="number" .. and not text.. (so user could change value using browser up/down buttons). is there any way to do it?
You can use ->textInput(['type' => 'number'] eg :
<?=$form->field($item, 'finalPrice', [
'options' => [
'tag' => 'div',
'class' => '',
],
'template' => '<span class="col-md-2 col-lg-2"><label class="control-label">Final item price</label>{input}{error}</span>'
])->textInput([
'type' => 'number'
])->label(false)?>
Try this . it worked for me
<?= $form->field($model, 'amount')->textInput(['type' => 'number']) ?>
Field like Phone Number/Membership No etc, some time we allow user only to enter numeric input in a text field. In such case applying pattern match rule work great for me.
Simply set a rule in the model class and you are done.
public function rules()
{
return [
...
[['contactno'], 'string', 'max' => 25],
[['contactno'], 'match' ,'pattern'=>'/^[0-9]+$/u', 'message'=> 'Contact No can Contain only numeric characters.'],
...
];
}
<?= $form->field($model, 'code')->textInput(['type'=>'number']) ?>
I'm using a partial view to display page header, that view accepts two variables one is Icon the other is a title.
pageHeader.blade.php:
<div class="page-header">
<div class="row">
<!-- Page header, center on small screens -->
<h1 class="col-xs-12 col-sm-4 text-center text-left-sm"><i class="fa {{$icon}} page-header-icon"></i> {{$title}}</h1>
</div>
and I'm using it like so:
#include('zdashboard._partials.pageHeader',['icon'=>'fa-pencil','title'=>'<strong>Editing</strong>'.$center->translations()->whereLang('en')->first()->name])
Sometimes I like to make one word strong or italic like the example above but, blade engine won't render the HTML tags I'm typing as part of title variable (the output like the photo down).
So is there any idea how to solve this? Am I doing it!
wrong?
The output
By default in Laravel 5 {{ $title }} construction wil be escaped.
If you don't want the data to be escaped, you may use the following syntax:
{!! $title !!}
Read more about Blade control structures: http://laravel.com/docs/5.0/templates#other-blade-control-structures
view
#if(Session::has('success'))
<div class="alert alert-success">
{!! Session::get('success')!!}
</div>
#endif
Controller
public function store(Request $request)
{
$this->validate($request, [
'product_code' => 'required|unique:products',
'product_name' => 'required',
'description' => 'required',
'price' => 'required',
'brand_id' => 'required',
'category_id' => 'required',
]);
$product = Product::create([
'product_code' => $request->input('product_code'),
'product_name' => $request->input('product_name'),
'description' => $request->input('description'),
'price' => $request->input('price'),
'brand_id' => $request->input('brand_id'),
'category_id' => $request->input('category_id'),
]);
return redirect()->route('products.index')->with('success',
"The product <strong>".$product->product_name."</strong> has successfully been created.");
}