I have a string coming from db like session_user_id denoting that I should grab the user_id from the session variable in PHP. This should ideally translate to $_SESSION[‘user’][‘id’] where the value exists. The following doesn’t seem to work. I have tried the variations like $ses…
Tag: php
PHP, MySQL date calculations
I’m trying to add a number of weeks to date, both will be taken from a database, I successfully fetch both needed but I can’t figure out how to make the calculations. So far I tried with “strtotime” but it gave me some weird results How do I do this the right way? The desired result sh…
Laravel 8 form to update database
I am creating a simple blog site with CRUD functionality in Laravel 8. I have done this before using the deprecated Laravel forms, but am now trying to do it using HTML forms. However, I am having some problem with the update part of the website. I have a controller called BlogsController with this function t…
Laravel Auth guard does not persist after redirect CustomUser
After redirecting from LoginController Auth::guard(‘user’)->user() returns null LoginConsumer LoginService LoginController Auth::guard(‘web’)->user() returns the right user in each of this layers. But on redirect to route(‘user-home’) (or to any route) the same Auth::…
PHP – Loop through UNION ALL query and add custom text once after the last item per category
I have a union query which joins several categories. I want to include the link after the last item of the category. The query goes like: … the result is The output should be like this: Here is the loop thanks to user @Luuk, but now I would like to include a link after the last item from the category.
Laravel 7 does not display flash message
I’m not sure if it has anything to do with it, but I believe it may be something related to my routes, I may be talking nonsense. No flash message is being displayed, I was only able to display a message by setting it to Session::put, retrieving it in the view and then deleting it. When I use with, with…
getting the value of an object with php [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question i have a code that is supposed to get the number of rows in a database that contains the ip ad…
Adding a namespace to the top of my PHP functions page results in the display of an entirely blank page (with no errors)
I am using PHP Version 7.3.25. I have started experimenting with PHP Namespaces on the server-side (not least because I use ESModules on the client-side and I fully appreciate the advantages of namespacing) but I have fallen at the first hurdle – it’s probably an obvious rookie error, but with no …
PHP compare arrays and remove NOT matched objects
I want to compare two arrays with each other and remove all objects from the first one who are NOT present in both arrays. The result should be array1 without the ‘AAAAAAAAAAAAAAA’ object. What I tried: Answer array_intersect_key is what you’re looking for. It takes two or more arrays, and r…
Redirect if there are no posts in the category Laravel
I want to redirect users back if they have selected a category that has no posts. I’ve tried something like this, but it doesn’t work: $check = Category::withCount(‘posts’)->first(); if($cheсk->…