Found 1060 Articles for PHP

How to obtain a list of all files in a public folder in Laravel?

Shilpa Kalangutkar
Updated on 30-Aug-2022 08:34:14

3K+ Views

To get the list of all files from public folder you can make use of File facade. To work with it you need to include following class use Illuminate\Support\Facades\File; Following files are present inside public folder −Example 1 To get all files from public folder

How to select count with Laravel's fluent query builder?

Shilpa Kalangutkar
Updated on 30-Aug-2022 08:18:19

18K+ Views

The fluent query builder in Laravel is an interface that takes care of creating and running the database queries. The query builder works fine with all databases supported in laravel and can be used to perform almost all database operations on it. The advantage of using a fluent query builder is that it has protection against sql injection attacks. It makes use of PDO parameter binding and you can be free to send your strings as you need. The fluent query builder supports a lot of methods like count, min, max , avg, sum that fetches you the aggregate values ... Read More

How to get distinct values for non-key column fields in Laravel?

Shilpa Kalangutkar
Updated on 29-Aug-2022 12:52:36

9K+ Views

Here are different ways that can give you distinct values for non-key column fields in Laravel. Assume we have created a table named students with the following query CREATE TABLE students( id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(15) NOT NULL, mail VARCHAR(20) NOT NULL, ... Read More

How to select all the column names from a table in Laravel?

Shilpa Kalangutkar
Updated on 29-Aug-2022 12:23:13

4K+ Views

Here are different ways to get the column names from a table in Laravel. Assume we have created a table named Students in MySQL database using the following query − CREATE TABLE students( id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(10) NOT NULL, email VARCHAR(15) NOT NULL, ... Read More

How to find a user in Laravel by Username?

Shilpa Kalangutkar
Updated on 29-Aug-2022 12:15:48

3K+ Views

There are various ways to find a Username in Laravel Using the first() method ExampleThe first() method returns the record found for the search value. It returns null if there are no matching records. To this method You can make use of the method first() to find the user by username.

How to alias a table in Laravel Eloquent queries using Query Builder?

Shilpa Kalangutkar
Updated on 29-Aug-2022 12:13:01

9K+ Views

Eloquent is a new object-relational mapper (ORM) that helps to interact with the database. With Eloquent each table has a mapping Model that takes care of all the operations on that table. Assume we have already created a table with the name student with the following contents − +----+---------------+------------------+-----------------------------+-----------------------------+---------+------+ | id | name | email | created_at | updated_at ... Read More

How to access the public directory in Laravel?

Shilpa Kalangutkar
Updated on 29-Aug-2022 11:59:49

6K+ Views

To get the file list from a public directory you can make use of the File facade class. To work with it you need to include the File class using the following statement – use Illuminate\Support\Facades\File; Assume we have the following files in the public folder − Example 1 Following Program tries to retrieve all the images from the public_folder −

How to Use OrderBy for Multiple Columns in Laravel?

Shilpa Kalangutkar
Updated on 29-Aug-2022 12:08:07

6K+ Views

The ORDERBY clause is used to arrange the columns in a table in ascending or descending order. By default it sorts the columns in ascending order, if you need to sort in descending order you should use DSC along with the clause. Syntax Following is the syntax of this statement − SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC; Assume we have created a table named Students in MySQL database using the following query − CREATE TABLE students( id INTEGER ... Read More

What is Fillable Attribute in a Laravel model?

Shilpa Kalangutkar
Updated on 29-Aug-2022 13:04:41

30K+ Views

The fillable property is used inside the model. It takes care of defining which fields are to be considered when the user will insert or update data. Only the fields marked as fillable are used in the mass assignment. This is done to avoid mass assignment data attacks when the user sends data from the HTTP request. So the data is matched with the fillable attributes before it is inserted into the table. To understand fillable attributes let us create a model as shown below php artisan make:model Student C:\xampp\htdocs\laraveltest>php artisan make:model Student Model created successfully. C:\xampp\htdocs\laraveltest> Now let ... Read More

How to validate an array in Laravel?

Shilpa Kalangutkar
Updated on 29-Aug-2022 11:43:24

6K+ Views

There are various ways to validate the input data in Laravel. One of those is the Validator class. The first step is that you need to include this class as shown below − use Illuminate\Support\Facades\Validator; When you work with an array you need to mention the keys and the rules to be used in the array. For example, consider the following array. Here, we are adding the keys, firstname, lastname, and address along with the values. Using rules we define all these elements are mandatory and of the data type String. $formData = array( 'firstname' => ... Read More

Advertisements