I’ve read the official documentation and all they say is that I should have a error_reporting() function located at the top of your main index.php file. But I don’t have index.php file in my project. My base controller is called core so to get to main index I go to www.mysite.dom/core/. So I guess…
Tag: php
How to display a readable array – Laravel
After I write: And after I refresh the browser I get an unreadable array. Is there a way to get that array in a readable format? Answer dd() dumps the variable and ends the execution of the script (1), so surrounding it with <pre> tags will leave it broken. Just use good ol’ var_dump() (or print_r…
500 Internal Server Error when trying to use ErrorDocument to handle request
I have this .htaccess file: However, when I go to localhost/example.php, it returns a 500 Internal Server Error. Any help please? Thanks. EDIT: The full error message that comes up is: Answer You’re most likely getting 500 due to looping error. Exclude 404.php from last rule as:
How do I traverse CakePHP relations?
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…
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…
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…
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: