How-to articles, tricks, and solutions about LARAVEL

Laravel - Eloquent or Fluent random row

In Laravel's Eloquent ORM, you can use the inRandomOrder method to retrieve a random row from the database.

Laravel - htmlspecialchars() expects parameter 1 to be string, object given

It looks like you are trying to use the htmlspecialchars() function in Laravel and are encountering an error that says "htmlspecialchars() expects parameter 1 to be string, object given".

Laravel - Model Class not found

If you are receiving an error stating that a specific Model class cannot be found in Laravel, there are a few possible causes:

Laravel - Session store not set on request

It sounds like you are trying to use the Laravel session, but it is not available in the current request.

Laravel - Using (:any?) wildcard for ALL routes?

In Laravel, you can use the (:any?) wildcard to match any URI for a specific route.

Laravel - where less/greater than date syntax

In Laravel, you can use the where method on a query builder or an Eloquent model to filter records based on a date column using less than or greater than operators.

Laravel 5 - Interface is not instantiable

This error message in Laravel 5 typically means that you are trying to instantiate an interface, but interfaces cannot be instantiated because they are only a contract for the methods that a class should implement.

Laravel 5 – Clear Cache in Shared Hosting Server

To clear the cache in Laravel 5, you can use the php artisan cache:clear command.

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 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 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 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.