PDOException SQLSTATE[HY000] [2002] No such file or directory

Laravel 4: Change “host” in the app/config/database.php file from “localhost” to “127.0.0.1” Laravel 5+: Change “DB_HOST” in the .env file from “localhost” to “127.0.0.1” I had the exact same problem. None of the above solutions worked for me. I solved the problem by changing the “host” in the /app/config/database.php file from “localhost” to “127.0.0.1”. Not … Read more

Laravel Add a new column to existing table in a migration

To create a migration, you may use the migrate:make command on the Artisan CLI. Use a specific name to avoid clashing with existing models for Laravel 5+: php artisan make:migration add_paid_to_users_table –table=users for Laravel 3: php artisan migrate:make add_paid_to_users You then need to use the Schema::table() method (as you’re accessing an existing table, not creating … Read more

Laravel requires the Mcrypt PHP extension

Do you have MAMP installed? Use which php in the terminal to see which version of PHP you are using. If it’s not the PHP version from MAMP, you should edit or add .bash_profile in the user’s home directory, that is : cd ~ In .bash_profile, add following line: export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH Edited: First you should … Read more

How to Create Multiple Where Clause Query Using Laravel Eloquent?

In Laravel 5.3 (and still true as of 7.x) you can use more granular wheres passed as an array: $query->where([ [‘column_1’, ‘=’, ‘value_1’], [‘column_2’, ‘<>’, ‘value_2′], [COLUMN, OPERATOR, VALUE], … ]) Personally I haven’t found use-case for this over just multiple where calls, but fact is you can use it. Since June 2014 you can … Read more

How to create custom helper functions in Laravel

Create a helpers.php file in your app folder and load it up with composer: “autoload”: { “classmap”: [ … ], “psr-4”: { “App\\”: “app/” }, “files”: [ “app/helpers.php” // <—- ADD THIS ] }, After adding that to your composer.json file, run the following command: composer dump-autoload If you don’t like keeping your helpers.php file … Read more

How can I remove a package from Laravel using PHP Composer?

Composer 1.x and 2.x Running the following command will remove the package from vendor (or wherever you install packages), composer.json and composer.lock. Change vendor/package appropriately. composer remove vendor/package Obviously you’ll need to remove references to that package within your app. I’m currently running the following version of Composer: Composer version 1.0-dev (7b13507dd4d3b93578af7d83fbf8be0ca686f4b5) 2014-12-11 21:52:29 Documentation … Read more

How do I get the query builder to output its raw SQL query as a string?

Use the toSql() method on a QueryBuilder instance. DB::table(‘users’)->toSql() would return: select * from `users` This is easier than wiring up an event listener, and also lets you check what the query will actually look like at any point while you’re building it. Note: This method works for query builder or Eloquent, however toSql() is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)