I’m trying to traverse the relations on CakePHP models. This is the database: I can access product attributes (product->attributes) on a product model but I cannot access the product attributes on Ad model (ad->product->attributes). Here is my code: And here is what I do in the views: What is w…
Laravel Eloquent inner join with multiple conditions
I have a question about inner joins with multiple on values. I did build my code like this in laravel. public function scopeShops($query) { return $query->join(‘kg_shops’, function($join) {…
php imagick won’t save PNG compressed but shows compressed in browser
I have the following code in PHP to take the screenshot of first page of the PDF. This code produces the PNG of 62kb only in the Google Chrome’s Resource monitor tab. But the image which is written by Imagick() is above 114kb. Just to make sure image isn’t compressed and or any other issues i have…
Need to remove squre bracket json_encode(array())
Below is my code and it return me json array but i need to remove square bracket from response $sql = “select user_loginId,user_password from wnl_user where user_loginId=’student01′ and user_password=…
Laravel Eloquent setting a default value for a model relation?
I have two models: This works fine, I can call $product->defaultPhoto->thumb and $product->defaultPhoto->full and get the path to the related image, and get all photos using $product->photos and looping through the values. The problem arises when the product does not have a photo, I can’t…
Warning: preg_replace(): Unknown modifier
I have the following error: Warning: preg_replace(): Unknown modifier ‘]’ in xxx.php on line 38 This is the code on line 38: How can I fix this problem? Answer Why the error occurs In PHP, a regular expression needs to be enclosed within a pair of delimiters. A delimiter can be any non-alphanumeri…
if and else statement just not working
Here is my if statement. I’m trying to have two differnt options. One is if the user is logged in and the other of course if they’re not. For the life of me I can not get these to work. This is a Word …
Laravel default orderBy
Is there a clean way to enable certain models to be ordered by a property by default? It could work by extending the laravel’s QueryBuilder, but to do so, you’ll have to rewire some of it’s core features – bad practice. reason The main point of doing this is – one of my models ge…
Auto redirecting to another pages at regular intervals
I want to create an application in PHP. concept is very simple, I want to just auto load every page randomly at a regular intervals. For example, if I entered to facebook.com, it would be auto load …
What is the exact equivalent of JS: something.toFixed() in PHP?
If I have a.toFixed(3); in javascript (‘a’ being equal to 2.4232) what is the exact equivalent command in php to retrieve that? I searched for it but found no proper explanation appended to the answers. Answer I found that sprintf and number_format both round the number, so i used this: