fail to update data into database - codeigniter

Controller
function edit($RegNo){
$data['row'] = $this->ManageTrenter code hereansfers->GetById($RegNo);
$this->load->view('admin/transferupdate', $data);
}
enter code here
public function update($RegNo){
$this->ManageT`enter code here`ransfers->update($RegNo);
redirect('admin/ManageTransfer/transfer');
}
Model
function GetById($RegNo){
return $this->db->get_where('user_transfer', array('RegNo' => $RegNo ))->row();
}
function update($RegNo){
$arr['School'] = $this->input->post('School');
$arr['Date'] = $this->input->post('Date');
$arr['RegNo'] = $this->input->post('RegNo');
$arr['Class'] = $this->input->post('Class');
$arr['New'] = $this->input->post('New');
$arr['Reason'] = $this->input->post('Reason');
$arr['UserId'] = $this->input->post('UserId');
$arr['Status'] = $this->input->post('Status');
$this->db->where(array('RegNo' => $RegNo));
$this->db->update('user_transfer', $arr);
}
View
RegNo);?>">
error occur
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: admin/transferupdate.php
Line Number: 12

replace
$this->db->where(array('RegNo' => $RegNo));
like this
$this->db->where('RegNo', $RegNo);

function update($RegNo){
$arr= array();
$post_data=$this->input->post();
$arr=(
'School' => $post_data['School'],
'Date' => $post_data['Date'],
'RegNo' => $post_data['RegNo'],
'Class' => $post_data['Class'],
'New' => $post_data['New'],
'Reason' => $post_data['Reason'],
'UserId' => $post_data['UserId'],
'Status' => $post_data['Status']
);
$this->db->where('RegNo', $RegNo);
$this->db->update('user_transfer', $arr);
}

Related

Trying to generating QR in laravel but get error Use of undefined constant

I am trying to pass code to generate a QR using chart.googleapis.com but I get Use of undefined constant
I can successfully do it here https://staging.veev.app/events/39 but I am having no luck doing it here https://staging.veev.app/groups/2/Young%20Professionals%20LA. Below is the code.
curl_close($ch);
$result = json_decode($result, true);
return $this->_loadView('client.pages.group')->with('group', $result);
$this->data['group'] = $result;
$group = $this->data['group'];
$group_data = array(
'prefix' => 'veev-groups',
'version' => 1,
'group_id' => $group['id'],
'group_name' => $group['name'],
//'group_name' => $group['result'],
//'merchant_id' => $group['merchant_id'],
'type' => 'groups',
'webpage' => $this->site_baseurl.'/groups/'.$group_id
);
$group_data = array_values($group_data);
$group_data = join("|||", $group_data);
$this->data['page_name'] = $group['name'];
$this->data['qr_srctest'] = 'https://chart.googleapis.com/chart?cht=qr&chs=250x250&chld=H%207C0&chl=' . $group_data;
return $this->_loadView('client.pages.group')->with('group', $result);

When collection->map returnes array then data in Collection raise error

In laravel 6 app I have collection defined as :
class PermissionCollection extends ResourceCollection
{
public static $wrap = 'permissions';
public function toArray($request)
{
return $this->collection->transform(function($permission){
return [
'id' => $permission->id,
'name' => $permission->name,
'is_checked' => !empty($permission->is_checked) ? $permission->is_checked : null,
'guard_name' => $permission->guard_name,
'created_at' => $permission->created_at,
];
});
}
}
I use it in a control, like :
$permissions = $user->permissions->all();
$userPermissionLabels= Permission
::get()
->map(function ($item) use($permissions) {
$is_checked= false;
foreach( $permissions as $nextPermission ) {
if($nextPermission->permission_id === $item->id) {
$is_checked= true;
break;
}
}
return [ 'id'=> $item->id, 'name'=> $item->name, 'is_checked' => $is_checked];
})
->all();
return (new PermissionCollection($userPermissionLabels));
and I got error :
Trying to get property 'id' of non-object
Looks like the reason is that collection->map returnes array of data, not objects.
If there is a way to fix it without creating new collection(using array) ?
MODIFIED :
I logged loging in my collection,
public function toArray($request)
{
return $this->collection->transform(function($permission){
\Log::info(' PermissionCollection $permission');
\Log::info($permission);
return [
'id' => $permission->id,
'name' => $permission->name,
'is_checked' => !empty($permission->is_checked) ? $permission->is_checked : null,
'guard_name' => $permission->guard_name,
'created_at' => $permission->created_at,
];
});
}
and I see in logs:
PermissionCollection $permission
array (
'id' => 1,
'name' => 'App admin',
'is_checked' => false,
)
local.ERROR: Trying to get property 'id' of non-object
The value is valid array, not null.
I mean I have already use this collenction in other part of the app, can I use it without creating a new one...
I think you get this error because you CollectionResource need to object of the Permission model, but in your case it is trying to get id from an array, after map function. Try to extend your model instead of returning an new array

How to define variable in controller in laravel

I have a URL used in blade template as:
href="{{ route('download', ['year' => $year, 'month' => $month, 'file' => $file_path]) }}"
when I am running my code then it is giving me an error as:
Undefined variable: year (View: C:\wamp64\www\Blog\employee-portal\resources\views\finance\invoice\edit.blade.php)
How can i define this $year variable in my controller?
In my controller the function is written as:
public function download($year, $month, $file, $inline = true)
{
$headers = [
'content-type' => 'application/pdf',
];
$file_path = FileHelper::getFilePath($year, $month, $file);
if (!$file_path) {
return false;
}
if ($inline) {
return Response::make(Storage::get($file_path), 200, $headers);
}
return Storage::download($file_path);
}
}
Edit function is written as:
public function edit(Invoice $invoice)
{
$projectStageBillings = $invoice->projectStageBillings;
$projectStageBilling = $projectStageBillings->first();
$client = $projectStageBilling->projectStage->project->client;
$client->load('projects', 'projects.stages', 'projects.stages.billings');
$billings = [];
foreach ($projectStageBillings as $key => $billing) {
$billing->load('projectStage', 'projectStage.project');
$billings[] = $billing;
}
return view('finance.invoice.edit')->with([
'invoice' => $invoice,
'clients' => Client::select('id', 'name')->get(),
'invoice_client' => $client,
'invoice_billings' => $billings,
]);
}
This error states that the view finance\invoice\edit.blade.php is missing the variable $year. And it is true, take a look at the return of your edit function:
return view('finance.invoice.edit')->with([
'invoice' => $invoice,
'clients' => Client::select('id', 'name')->get(),
'invoice_client' => $client,
'invoice_billings' => $billings,
]);
You are not sending any $year variable to the view here (the variables sent to the view are invoice,clients,invoice_client and invoice_billings.
To solve your problem, just send a $year variable to the view and you'll be ok :)

How to pass array in POST API?

I'm trying to post booking content with array of passengers but it always return invalid argument supplied for foreach(). What seems to be the problem ?
public function postBooking(Request $request)
{
$user = JWTAuth::parseToken()->authenticate();
$booking = Booking::create([
'service_name' => $request->get('service_name'),
'service_package' => $request->get('service_package'),
'travel_date' => $request->get('travel_date'),
'travel_day' => $request->get('travel_day'),
'travel_time' => $request->get('travel_time'),
'remark' => $request->get('remark'),
'booking_name' => $request->get('booking_name'),
'mobile_number' => $request->get('mobile_number'),
'email' => $request->get('email'),
'nationality' => $request->get('nationality'),
'user_id' => $user->user_id,
]);
$passengers = $request['passengers'];
if(is_array($passengers))
{
foreach($passengers as $passenger)
{
$passenger = Passenger::create([
'passenger_name' => $passenger['passenger_name'],
'ic_passport' => $passenger['ic_passport'],
'booking_id' => $booking->booking_id
]);
}
}
$response = (object)[];
$response->booking = $booking->makeHidden('users');
$response->passengers = $passengers;
return response()->json(['data'=>$response, 'status'=>'ok']);
}
var_dump the $passengers, in my opinion ,the way u get the data from $request is wrong, u show use var_dump()or dd() to see the structure of $request and mostly u can solve the problem.

Call to undefined method Product_model::product()

public function save_edit() {
parent::__save_edit();
$this->db = $this->load->database('default', true);
$this->load->model('product_model','',TRUE);
$id = $this->input->post('item_id');
$array_item = array(
'item_name' => $this->input->post('item_name'),
'note' => $this->input->post('item_note'),
'stock' => $this->input->post('item_stock'),
'price' => $this->input->post('item_price'),
'unit' => $this->input->post('item_unit')
);
$this->load->model('product_model');
$this->product_model->update($id,$array_item);
redirect('index.php/product');
}
public function edit(){
$this->db = $this->load->database('default', true);
$this->load->model('product_model');
**$data['product'] = $this->product_model->product($this->uri->segment(3))->row_array();**
$this->load->view('index.php/product_edit',$data);
}
error at line
$data['product'] = $this->product_model->product($this->uri->segment(3))->row_array();
your get this error because. your model i.e "product_model" does not contain any product function.
Hence you get "Call to undefined method Product_model::product()" error

Resources