Laravel Articles

Page 3 of 5

How to delete a file from the public folder in Laravel?

Shilpa Kalangutkar
Shilpa Kalangutkar
Updated on 30-Aug-2022 5K+ Views

You can make use of the File facade class. To work with File facade you need to include the class as shown below − use Illuminate\Support\Facades\File; Here is a list of examples that shows how to delete the files from the public folder. The files details in the public folder are as follows –  Example 1 To delete files using delete() method from File façade. The delete() method will delete the files given. It can take a single file or an array of files as an input. You can delete a single file from the public folder as ...

Read More

How to pass an array as a URL parameter in Laravel?

Shilpa Kalangutkar
Shilpa Kalangutkar
Updated on 30-Aug-2022 12K+ Views

To pass an array as URL parameter you can make use of php built-in function http_build_query(). The http_build_query() returns you an URL-encoded query string. Example 1 Using http_build_query() Following is an example of this method − $data = array( 'field1' => 'test', 'field2' => 'xyz' ); echo http_build_query($data) . ""; Output The output of the above code is − field1=test&field2=xyz The following example shows how to make use of http_build_query() when you have an array and the same needs to pass as a URL parameter.

Read More

How to get the last inserted ID using Laravel Eloquent?

Shilpa Kalangutkar
Shilpa Kalangutkar
Updated on 30-Aug-2022 17K+ Views

Eloquent is a new object relational mapper (ORM) that helps to interact with database. With Eloquent each table has a mapping Model that takes care of all the operations on that table. Model in laravel represents the table in the database. For example if you have table customers, the model name will be customer, for users it will be user, employees it will be employee. The table name has to be plural and the model name has to be singular. This is a pattern followed, but that does not stop you from using the naming convention of your choice for ...

Read More

How to select certain fields in Laravel Eloquent?

Shilpa Kalangutkar
Shilpa Kalangutkar
Updated on 30-Aug-2022 8K+ Views

Laravel Eloquent provides many ways to select the fields that you need from the table. Here are a few examples that show how it can be done. Example 1 The following is an example of this −

Read More

How to get the Current URL inside the @if Statement in Laravel?

Shilpa Kalangutkar
Shilpa Kalangutkar
Updated on 30-Aug-2022 2K+ Views

To get the current URL you can use the methods explained in the example below − Example 1

Read More

How do you check if a field is NOT NULL with Eloquent?

Shilpa Kalangutkar
Shilpa Kalangutkar
Updated on 30-Aug-2022 5K+ Views

In the Eloquent Model you can make use of whereNotNull() method to get the not null values from the database. Example 1 In this example we are checking the field rememer_token if it’s NOT NULL.

Read More

How to add a new value to a collection in Laravel?

Shilpa Kalangutkar
Shilpa Kalangutkar
Updated on 30-Aug-2022 13K+ Views

Collection in Laravel is an API wrapper that helps you deal with different operations to be performed on arrays. It makes use of the class Illuminate\Support\Collection to deal with arrays in Laravel. To create a collection from a given array you need to make use of the collect() helper method that returns a collection instance. Later you can use a chain of methods like converting to lowercase, sorting on the collection instance. Example 1

Read More

How to check if a user email already exists in Laravel?

Shilpa Kalangutkar
Shilpa Kalangutkar
Updated on 30-Aug-2022 5K+ Views

There are many ways you can test if email exists. One way is using the validator class. To make use of validator you need to include the class as shown below; use Illuminate\Support\Facades\Validator; Example 1 The example shows how to make use of Validator to check if email is registered or not.

Read More

How to order the results of related models in Laravel Eloquent?

Shilpa Kalangutkar
Shilpa Kalangutkar
Updated on 30-Aug-2022 516 Views

Laravel Eloquent comes with the orderBy() method that can be used to order the results from the model. We are going to make use of Users table as shown below − Let us create another table user_roles with following data − Example 1 Following examples show how to make use of orderBy to order results.

Read More

How to update a query on Laravel Fluent using db::raw?

Shilpa Kalangutkar
Shilpa Kalangutkar
Updated on 30-Aug-2022 6K+ Views

You can make use of db::raw when you want to test or use some arbitrary string inside the fluent query builder. To work with db::raw you have to make use of the DB facade class − use Illuminate\Support\Facades\DB; Here are a few examples that show the use of DB:raw(). Example 1

Read More
Showing 21–30 of 45 articles
Advertisements