Store Helpers functions in mysql Table Undefined variable $employee_id - laravel

I'm working on Laravel and I have functions in the helper. I want to store the functions in the data base (mirgation).
Ex function in the helper :
function PayrollSalary($employee_id, $employor_id)
I can't store the below line when I migrate the database. I have an error message (Undefined variable $employee_id).
DB::table('payroll_model_items')->insert(array(
'code'=>"BaseSal",
'name'=>"Base Salary",
'value'=>"<div>{{PayrollSalary($employee_id, $employor_id)}}</div>",
'sequence'=>"0000101",
'created_at'=>date('Y-m-d H:m:s'),
'updated_at'=>date('Y-m-d H:m:s')
));
Can anyone help?
Thank you

Related

Array view not working on Laravel Blade Template. (Undefined variable: )

I get the counts of 3 different tables with 3 different SQL queries.
Here :
$Count['FirstRecords']= DB::table('table1')->where('Id',$slug)->count('Id');
$Count['SecondRecords']= DB::table('table2')->where('Id',$slug)->count('Id');
There aren't any problems when I check the content on controller with print_r function. I get an output like the following:
Array
(
[FirstRecords] => 178
[SecondRecords] => 302
)
Then I sent this array to the blade template via view function.
return view('View/CountView',['Records' => $Count]);
I'm trying to print on the blade like this:
{{$Records->FirstRecords}}
I get the following error every time when I trying to print this array on the blade template.
Undefined variable: Records (View: {Path}

How to get Session data in Codeigniter

Fatal error: Call to Undefined method CI_Session::get_userdata()
in/application/xamp/htdocs/application/models/articles_model.phI
I face a this error; how do I resolve this?
Its not correct method to get session data in code igniter.
To assign vale to session use
$this->session->set_userdata('name',$value);
To fetch value of session use
echo $this->session->userdata('name');
To pass an array
$temp = array('name'=>'John Doe','login'=>1);
$this->session->set_userdata('details',$temp);
To get array session data
print_r($this->session->userdata('details'));
$details = $this->session->userdata('details');
echo $details['name'];
Fatal error: Call to Undefined method CI_Session::get_userdata()
get_userdata() change into userdata()
Because it's the userdata() built-in session function in Codeigniter.
You can't change this

date callback function in ignited datatables not working

im using ignited datatables library for codeigniter
this is my code:
function datatable()
{
$this->datatables->select('id,name,created')
->unset_column('id')
->edit_column('created', '$1',date('Y-m-d H:i:s','created'))
->from('categories');
echo $this->datatables->generate();
}
created is unix timestamp and i want to show date in table.
but when i use callback function like this or in helper it doesn`t work. php warning:
A PHP Error was encountered
Severity: Warning
Message: date() expects parameter 2 to be long, string given
Filename: controllers/categories.php
Line Number: 22
created is unix timestamp value in database. when i pass it to date function the database value does not pass to date function. when i var_dump it it shows $1 instead of real value of database. in other functions it works ok. but in date function returns error.
Use this
$this->datatables->select('id,name,created')
->unset_column('id')
->edit_column('created', '$1',timestamp('Y-m-d H:i:s'))
->from('categories');
Timestamp Manual

Displaying an array element in a View - Laravel

I am trying to output a variable like this: <h1>{{ $unitcode }}</h1>
I have this code making that variable:
// Validation was successful.
$inputcode = Input::get('unitcode');
// First validation is successful. Next to check that it is a correct unit code.
$unitcode = DB::table('unitcodes')->where('unitcode', $inputcode)->first();
if(!$unitcode) {
// Input code is wrong. The unit does not exist.
return Redirect::route('get-buy')
->with('global', 'That unit code does not exist. Try again.');
} else {
// Success! Unit code exists!
return View::make('showbooks')
->with('unitcode', $unitcode);
}
When I run everything it gives me this:
ErrorException (E_UNKNOWN)
Array to string conversion (View: ..BLAH goes on to display path to view.
How can I get it to display the variable I want that was pulled from the DB?
Thanks!
In Laravel's DB abastraction layer a row from a database table (result of a SELECT ... LIMIT 1 - DB::...->first()) is an array.
You can send any kind of variables using View::...->with but you need to use them properly in the template itself ('showbooks').
You most probably are doing a {{{ unitcode }}} in the template which is actually similar to executing an echo $unitcode. Now if $unitcode is an array and echo requires a string then PHP automatically tries to convert it and fails (ErrorException (E_UNKNOWN)
Array to string conversion...).
What you need to do is use it correctly:
{{{ unitcode['unitcode'] }}}
And this will work because $unitcode is a key-value dictionary where each key is a column from the DB table with its associated value.

Get parameters from another component

I have two custom components that reference an external database. In component1 I set the parameters necessary to connect to that external DB.
Is there I way that I can use the parameter set in component1 within component2?
my code within my model in component2:
$app = JFactory::getApplication();
$params = $app->getParams('com_component1');
advises me of a fatal error:
Fatal error: Call to undefined method JApplicationAdministrator::getParams() in /var/www....
Should I just stop being lazy and redefine the same parameters in component2, or is there a reasonable solution?
Try using the following code.
$params = JComponentHelper::getParams('com_component1');
$test = $params->get('param_name');
To get parameters, you need to use JComponentHelper, not JFactory.

Resources