i'm using datatables serverside to get all the data from 2 tables and display them. One of the values that i get is encrypted in the database.
Is there any way to decrypt this value within the blade template before displaying it?
I'm editing other values of the tables using
"mRender": function (data, type, full) {}
Tried to use Illuminate\Support\Facades\Crypt::decrypt($value) but it has no result.
I got the solution as below.
{{ \Crypt::decrypt($var) }}
You can use only decrypt function too
{{ decrypt($var) }}
full[5] is a javascript variable, if you pass it to Crypt::decrypt() it will not know it is a javascript variable, but a php constant, because it is inside <?php ?>.
You need to "rebuild" your data the way you want it to be displayed in datatables.
To do so, use editColumn method:
Route::get('/serverSideSymv', ['as' => 'serverSideSymv', 'uses' => function () {
$symv = App\Symvolaia::Select('table1.*')->join('table2', 'table1.insurancecompanyid', '=', 'table2.id')->join('table3', 'table1.simvalomenos', '=', 'table3.kodikos_pelati')->select('filed1,field2,field3,......');
return Datatables::of($symv)
->editColumn('your_column', function($data) {
return Illuminate\Support\Facades\Crypt::decrypt($data->your_column);
})
->make();
});
Related
I'm new to Laravel, I'm trying to follow along with this tutorial
https://laravel.com/docs/7.x/blade#displaying-data
I want to assign a value to a variable and then display it in the view but I don't know where I should do it. I tried to add this snippet
Route::get('greeting', function () {
return view('welcome', ['name' => 'Samantha']);
});
to the web.php file and then display it in the view like this hello, {{name}} but I either get an error or just a plain text:
hello, {{name}}
I'm reading the documentation but I can't figure out where or how to assign values to variables and then display it.
My view named welcome.blade.php has this:
<h1>Example</h1>
Hello, {$name}
In my web.php file I have this:
<?php
use Illuminate\Support\Facades\Route;
Route::get('greeting', function () {
return view('welcome', ['name' => 'Samantha']);
});
It doesn't give me any error. Just shows Hello {$name} instead of Samantha
you are missing the $ sign in your blade.
hello, {{ $name }}
I am using this module .
I defined my Breadcrumbs, and now I'm trying to render in my blade template by doing the following :
{!! Breadcrumbs::render($breadcrumbs) !!}
The value of $breadcrumbs being "controlled" by my controller.
The problem is that I would like to be able to pass an array of arguments to this render() method, and not only simple strings. Indeed, here are some Breadcrumbs I declared :
Breadcrumbs::register('home', function($breadcrumbs)
{
$breadcrumbs->push('Home', route('home'));
});
/* .... etc .... */
Breadcrumbs::register('style', function($breadcrumbs, $style_name, $style_slug)
{
$breadcrumbs->parent('styles');
$breadcrumbs->push($style_name, route('style', $style_slug));
});
In this situation, I need to be able to pass an array of arguments to the render() method, which will be sent by the Controller to the View.
I tried the following :
{!! call_user_func_array(Breadcrumbs::render, $breadcrumbs) !!}}
But I get the following error :
Undefined class constant 'render'
This module has a renderArray() method. Next time, I'll read the documentation till the end :)
Hi I send a form in my contact.blade.php. I read in order to use the PUT method you have to create a hidden input field which contains the method.
#if($do == 'edit')
{{ Form::model($contact, array('method' => 'PUT', 'route' => array('contact.update', $contact->id), 'id' => $do=='edit' ? $do.$contact->id : $do.$contact_type_id, 'form_id' => $do=='edit' ? $do.$contact->id : $do.$contact_type_id)) }}
{{ Form::hidden('_method', 'PUT') }}
#endif
....
{{ Form::submit('speichern', array('class' => 'btn btn-primary')) }}
</div>
{{ Form::close() }}
The route:
Route::put('/contact/{id}', array(
'uses' => 'ContactController#update',
'as' => 'contact.update'
));
The Controller:
public function update($id)
{
dd(Input::all());
// //get user account data
// $user = User::find( Auth::id() );
// // validate input
// $v = Contact::dataValidation( Input::all() );
return Redirect::Route('user.edit', 1)->withSuccess("<em>Hans</em> wurde gespeichert.");
Q1:
As soon as I call dd(Input::all()); I don't get redirected any more, instead I see a json with my form values.
Q2:
I'm just debugging this so I didn't program it. So my second question is:
From my understanding dd(Input::all()); gets all my form data. So don't I need to store it anyways somewhere?
Q1: dd() terminates the script, hence why you are not getting redirected. It's used as a tool to essentially break and examine what is going on.
http://laravel.com/docs/4.2/helpers
Q2: You will still need a model to feed the Input::all data into. Input::all simply fetches the submitted data, it doesn't do anything with it. It ultimately depends on your use case, sometimes you may want to email the data, but obviously most times you would what to store it against your persistence layer (read database / datastore)
Question 1
when you use DD, it will show the data and stop at that line.
DD
Dump the given variable and end execution of the script.
more information you can read it here DD in DD session.
Question 2
I'am not sure about 2nd question but if you want to get value from all input you could us Input::all();
more information All input in Getting All Input For The Request session
I got value from database and then i need to set those value to textbox. I have created a controller file with the method name of edit look like below
userdata.blade.php:
public function edit($id)
{
echo "You have clicked edit link".$name;
$editdata = DB::table('newuser')->where('Id','=',$id)->get();
return View::make('editdata',array('list' => $editdata));
}
I have passed array of value as parameter to the view file.now i need to diaplay the value of name to textbox.how to do that in html page using laravel. My html page look like below
editdata.blade.php:
<html>
<head></head>
<body>
<div>
{{Form::open(array('url' => 'login', 'method' => 'post'))}}
{{Form::label('name','Name',array('id'=>'label-name'))}}
{{Form::text('name',{{$list->Name}}}}
{{ Form::close() }}
</div>
</body>
</html>
can anyone tell me that what mistake i did.Thanks in advance
Just remove the curly brackets, you are already "inside" PHP code and don't need them:
{{ Form::text('name',$list->Name) }}
Also you get a collection from your controller you probably want to do:
$editdata = DB::table('newuser')->where('Id','=',$id)->first();
Or even:
$editdata = DB::table('newuser')->find($id);
get() returns a collection (multiple rows) and not the model itself. You can use User::find($id) which gives you direct access to the model with the specified Id.
When not using eloquent just replace get() with first()
I'm using Laravel framework and i have two dropdown lists of which both are reading data from the database tables,
the first one it read all the records from the table and populate it on the select list
here is my code:
<div class="form-group">
{{Form::select('advertiserName', Advertiser::all()->lists('advertiserName', 'advertiserId'))}}
</div>
it display the advertiser name and also passes the id on the advertiser.
The second dropdown i want it to display all the Brands related to the above selected advertiser.
here is my code:
<div class="form-group">
{{Form::select('brandName', Brand::where('advertiserId', '=', '3')->lists('brandName', 'id'))}}
</div>
The advertiserId is the foreign key of the advertiser and 3 must be replaced by the the advertiserId you selected on the first dropdown list, basically i want to pass variable from the first select list to the second one
Thank you
Basically you need to use AJAX to get data for Second Dropdown based on option selected from first dropdown.
Create Second Dropdown inside specific div and After ajax Call replace contect of div from ajax response.
As stated, the best way to achieve this is via an AJAX request. Here is an example of how you can achieve this functionality.
Firstly create a view partial that renders the select box for brands. Something like this (this code is based on Bootstrap 3):
{{ Form::label('brandName', 'Brand', ['class' => 'control-label col-sm-2']) }}
<div class="col-sm-10">
{{ Form::select('brandName', $brands, null, ['class' => 'form-control']) }}
</div>
Now, in your routes.php file add the following route:
Route::get('brand-list/{id}', ['as' => 'brands', 'uses' => 'BrandsController#brandList']);
In your BrandsController.php file (or whatever controller your using to handle this) add a method called brandList();
public function brandList($id)
{
// Return an array of brands for the selected advertiser name ID if available
$brands = $this->brand->where('advertiserId', $id)->lists('brandName', 'id'); // I'm using dependency injection here so you'll need to assign your Brand model to the $this->brand property of this classes constructor method
if ( ! isset($brands))
{
$brands = ['No brands available' => null]; // return a generic array containing 1 item with a value of null so you can handle it in your view. You could also return something else here such a boolean of false and then handle that in your AJAX request to return an error or info message
}
return View::make('brands.partials.select', compact('brands'));
}
Now for the AJAX:
$('#advertiserName').change(function(e) {
var advertiserId = $(this).val();
var url = '/brand-list/' + advertiserId;
$.get(url, function(data) {
$('.brands').html(data); // The returned view with the brand select input
});
});
Then in your initial form view you'll want to create an empty div with a class of .brands that we'll use to populate with the HTML returned via our AJAX request. Something like this if you're using Bootstrap 3 for example:
<div class="form-group brands"></div>
This should work as you need but I haven't tested this code, so if you have any issues let me know. Obviously this is generic code based on the info available and there are many ways to skin a cat.