In my controller, I am calling a model function with the following:
$this->sales_model->softdelete_order($this->input->post('ordernumber'));
what I want to do, in my model is
update Customer_Order_Summary set Deleted='1' where CustomerOrderID='123'
where 123 is $this->input->post('ordernumber')
My Model syntax is:
function softdelete_order($q){
$this->db->set('Deleted','1');
$this->db->where('CustomerOrderID', $q);
$query = $this->db->update('Customer_Order_Summary');
}
This is not working or outputting any errors.
The model is preloaded and the post information is posting and echoing correctly so purely a model syntax issue I think.
Help appreciated as always.
Thanks,
After
$query = $this->db->update('Customer_Order_Summary');
add
$this->db->last_query();
to see your query and you can repair it from there.
Try using
$this->db->set('Deleted',1);
If not working post your exact error
Related
My code currently looks like this:
foreach ($things as $thing) {
$ids[] = $thing->id;
}
dd(Other::whereIn('thing_id', $ids)->get());
Thing model has many Other
public function others()
{
return $this->hasMany(Other::class);
}
It's working, but can I achieve this functionality without using the foreach? It doesn't seems to be clean for me. I've tried to give whole collection to where in like this:
dd(Other::whereIn('thing_id', $things)->get());
but this only returned where id was 1.
I'm looking for help to clean up this code, any help appreciated.
There is a function called "pluck"
You can apply it on a collection as following
$collection->pluck('id');
More can be seen on docs
https://laravel.com/docs/7.x/collections#method-pluck
I've already found a way to clean it up a bit, instead of foreach I can simply use :
$ids=$things->pluck('id');
If there's a cleaner way pls show me :)
I tried to dd some data but it just show full html code
public function checkPayment()
{
$payment = Payment::where('status', 3)->get();
dd($payment[0]->order->account_executive->name);
return view('admin.order.paymentCheck', compact('payment'));
}
but it render like this
i tried dd(1) or dd('a') but the result is the same.
i expected dd like this
You are trying to access your collection as if it's an array, which may be causing an error that is not allowing the dd to execute properly. If you want to dd the first member of your $payments collection, try this:
$payments = Payment::where('status', 3)->get();
dd($payments->first()->order->account_executive->name);
See if that helps and let me know if it's still dumping out the html. It shouldn't.
answers from smankusors
remove the header(Content-Type) in provider or middleware or routes.
I am new to Laravel. I am using Laravel 5.4. For some purpose, I need the current route. For this, I am using the following code in my controller.
$name = Route::currentRouteName();
dd($name);
But, its always showing null. Any help will be appreciated.
I don't know what's problem with your code but you can get URL of current route with following way as well,
$name = URL::current();
To view value you can dump $name,
dd($name);
You can try with following:
$name = Route::current()->getName();
dd($name)
This is the default laravel notifications data field
{
"type":"Update Appointment",
"appointment_id":"379",
"date":null,
"updated_by":"Mahir",
"status":"2"
}
In controller i want to get all notifications with status = 2 and mark as read
Laravel 5.3 doc shows
$user = App\User::find(1);
foreach ($user->unreadNotifications as $notification) {
$notification->markAsRead();
}
How do i modify this to get all notifications with status = 2
Update : looking for something like this
$noti = $user->unreadNotifications->where('data->status',"2");
Note : my database doesn't support json data type.
According to laravel 5.6: JSON Where Clauses
and work with MySQL 5.7
I hope this answer help you
I think, you can create your own channel, (see also Illuminate\Notifications\Channels\DatabaseChannel), where you can override send() method, for saving your notifications. Before that, you can write your migration to update "notifications" table to add your custom filtering field.
See: https://laravel.com/docs/5.5/notifications#custom-channels
Sorry for my English. Hope, you'll understand.
$user = $user->unreadNotifications->where('data.complaint_id',1);
Its work fine for me, I hope it's helpful for you.
I get results with join query but in view when I want to show it, it says: trying to get property of non object. I am working over a simple blogging system and I am trying to get blogs from following friends. Here is my view:
#foreach($blogposts as $posts)
<h4>{{ $posts->title }}</h4>
#endforeach
I am sure the problem is at view but I added my controller too, maybe needed and here is my controller:
$posts=DB::table('following')
->join('page_posts', 'following.p_id', '=', 'page_posts.p_id')
->select('page_posts.*')
->where('u_id','=',Auth::User()->id)
->orderBy('updated_at','desc')
->get();
return View::make('index')->with('blogposts',$posts);
Help me with this please.
Try this. You need to pass the values as like this.
return View::make('index',array('blogposts'=>$posts));
I should have used eloquent to solve this means that my controller should be like this:
$posts=following::join('page_posts', 'following.p_id', '=', 'page_posts.p_id')
->select('page_posts.*')
->where('u_id','=',Auth::User()->id)
->orderBy('updated_at','desc')
->get();
return View::make('index')->with('blogposts',$posts);
The problem solved. I posted the answer, because someone else maybe needs.