Code Answers

Laravel: One to Many to Many, retrieve distinct() values

Laravel 4 Project, using Eloquent ORM. I have three tables: customers, orders and products (+ 1 pivot table order_product). Customers are linked one-to-many to Orders. Orders are linked many-to-many to Products. Customers 1-->N Orders NN Products I would like to have a method on Customer model that retrieves a list of products that custom...

Laravel 4 – unserialize(): Error at offset 0 of 32 bytes

When I install Laravel 4, I receive this error: ErrorException unserialize(): Error at offset 0 of 32 bytes C:\xampp\htdocs\blog\laravel\bootstrap\compiled.php return unserialize($this->stripPadding($this->mcryptDecrypt($value, $iv))); If I modify return like this: return unserialize(base64_decode($this->stripPadding($this->mcryptDecrypt($val...

Laravel IoC and singleton pattern

I'm trying to use Laravel IoC by creating a singleton object. I'm following the pattern from tutorial as below. I have put a Log message into object (Foobar in this example) constructor and I can see that object is being created every time I refresh page in browser. How is the singleton pattern meant for Laravels IoC? I understood that its sha...

Php – Laravel – artisan command not working

I am getting started with using laravel on Mac and am using MAMP. I am using the `artisan' command with laravel in php. php artisan migrate:make create_users_table --table=users --create But it is giving me this error php artisan migrate:make create_users_table --table=users --create PHP Warning: PHP Startup: Unable to load dynamic library '...

Laravel 4 hasMany with WHERE clause

Not sure if this is the correct way to add an additional query to the hasMany argument but was unsuccessful. Is this possible? public function menuItems($parent=false){ if($parent){ $menuItems = $this->hasMany('MenuItem')->where('parent',$parent); }else{ $menuItems = $this->hasMany('MenuItem'); } return $menuItem...

Laravel Migration – Update Enum Options

I'm trying to add an enum option to a table (without losing the current dataset) using the schema builder. The only thing I've really been able to find about column alteration is http://www.flipflops.org/2013/05/25/modify-an-existing-database-column-in-a-laravel-migration/ and I believe that was written for Laravel3. Even so, I tried using the ...

Php – SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: NO) (SQL: select * from `rooms` order by `order_by` asc)

my code run fine in localhost but when i uploaded it on the serve following error show Illuminate \ Database \ QueryException (1045) SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from rooms order by order_by asc) Previous exceptions SQLSTATE[HY000] [1045] Access denied for user 'root'@'loc...

Laravel 6 passport returns 400 Bad request on wrong credential

I use Laravel 6 passport grant password for my Vue backend. When i send right credential to oauth/token it works and returns token, but when i send wrong (email/password) it returns 400 instead of 401 with this message. { "error": "invalid_grant", "error_description": "The provided authorization grant (e.g., authorization code, reso...

Laravel 6.0.3 Not Loading Key Resources App.js or App.css 404 Not Found

To setup my project I ran: laravel new cms composer require laravel/ui php artisan ui:auth php artisan migrate However, when I go to http://cms.test/login I am shown the login page: And get two 404 errors for missing resources: http://cms.test/js/app.js net::ERR_ABORTED 404 (Not Found) http://cms.test/css/app.css What could be the reason for...

Php – Fatal error: Uncaught ReflectionException: Class config does not exist

I'm working on an e-commerce project on Laravel 5.8, but since I accidently ran "laravel new" command on the project's folder I get this error when I'm trying to launch the project on a local server: Fatal error: Uncaught ReflectionException: Class config does not exist in C:\wamp64\www\e-commerce\vendor\laravel\framework\src\Illuminate\Conta...

PHP Laravel session flash alert message not showing

In my laravel-app users can check a checkbox on the contact form if they want to subscribe for a newsletter. When the checkbox is checked and the submit the form, there is a check in the controller, if the user already is subscribed and if so, a flash alert/message should appear with something like 'You are already subscribed'. Now, the check i...

Php – file_put_contents failed to open stream: No such file or directory , Install

i cloned a laravel project from bitbuket . also run all necessary command to get all vendors files like : composer dump-autoload composer install php artisan cache:clear php artisan clear-compiled also deleted the file /public_html/bootstrap/cache/config.php but i am getting the below error when i try to launch the project : file_put_content...