How-to articles, tricks, and solutions about PHP

Laravel 5 Application Key

In Laravel, the application key is a unique, random string that is used to encrypt user sessions and other sensitive data.

Laravel 5 change public_path()

In Laravel 5, you can change the value of the public_path() function by modifying the 'public' key in the config/filesystems.php configuration file.

Laravel 5 Clear Views Cache

To clear the cache for your views in Laravel 5, you can use the view:clear Artisan command.

Laravel 5 getting ID from URL

In Laravel 5, you can get the ID from the URL by using the $request object or by defining a route parameter in the web.php file.

Laravel 5 How to switch from Production mode

To switch from production mode to development mode in Laravel 5, you can use the php artisan down command.

Laravel 5.2 - pluck() method returns array

The pluck method is used to retrieve a list of a single column from a database table.

Laravel 5.3 multiple file uploads

In Laravel 5.3, you can use the Request object's file method to handle multiple file uploads.

Laravel back button

In Laravel, you can use the back function to redirect the user to their previous page.

Laravel Carbon: how to change timezone without changing the hour?

In Laravel, you can use the setTimezone method on a Carbon instance to change the timezone without changing the hour.

Laravel Check If Related Model Exists

In Laravel, you can use the exists method on a relationship to check if it has any related models.

Laravel csrf token mismatch for ajax POST Request

The csrf_token error you are encountering occurs when you are making a POST request to your Laravel application and you have not included a valid CSRF token in the request.

Laravel Delete Query Builder

In Laravel, you can use the Query Builder to delete records from a database table.

Laravel Eloquent - Attach vs Sync

Here's an example that demonstrates the difference between using attach() and sync() in Laravel Eloquent:

Laravel Eloquent inner join with multiple conditions

To perform an inner join with multiple conditions using Laravel's Eloquent ORM, you can use the join method on a query builder instance.

Laravel Eloquent LEFT JOIN WHERE NULL

In Laravel, you can use the leftJoin method on a query builder instance to perform a left join, and then use the whereNull method to only include records where a column from the right-hand table is null:

Laravel Eloquent Sum of relation's column

You can use the sum method on an Eloquent relation to get the sum of a column's values.

Laravel get name of file

In Laravel, you can use the getClientOriginalName() method to retrieve the original file name of an uploaded file.

Laravel Migration table already exists, but I want to add new not the older

If you have an existing table in your database that you want to add new columns to using a Laravel migration, you can use the Schema::table method to modify the existing table.

Laravel migration table field's type change

To change the type of a field in a table using a migration in Laravel, you can use the change method on the Schema facade.

Laravel orderBy on a relationship

In Laravel, you can use the orderBy method on a relationship to sort the results of the relationship by a given column.

Laravel Query Builder where max id

In Laravel, you can use the Query Builder's max method to retrieve the maximum value of a specific column.

Laravel says "Route not defined"

There could be several reasons why you are seeing this error message in Laravel.

Laravel Socialite: InvalidStateException

The InvalidStateException is thrown by Laravel's Socialite package when the state parameter provided in the OAuth redirect URL does not match the one stored in the session.

Laravel storage link won't work on production

There are several reasons why the Laravel storage link may not be working on production.

Laravel: Error [PDOException]: Could not Find Driver in PostgreSQL

It looks like you are trying to connect to a PostgreSQL database from your Laravel application, but the PDO (PHP Data Objects) extension is not installed or enabled in your PHP environment.