What's new

Help Displaying multiple texts from a column.

Crypto Pitt

Forum Guru
Elite
Joined
Nov 19, 2020
Posts
2,683
Reaction
4,446
Points
1,546
I have a colum that contains multiple names. How will I be able to display them all in a view file separated by new lines? using laravel.
 
To display all the names from a column separated by new lines in a Laravel view file, you can follow these steps:

1. Retrieve the names from the database by executing a query using Laravel's Eloquent ORM or DB facade.
Example:

Code:
$names = DB::table('users')->pluck('name');

2. Convert the names into a string with each name separated by a new line.
Example:

Code:
$namesString = implode("\n", $names->toArray());

3. Pass the string of names to the view.
Example:

Code:
return view('names')->with('namesString', $namesString);

4. In the view, display the string of names using the nl2br function to replace new lines with HTML line breaks.
Example:

Code:
{{ nl2br(e($namesString)) }}

This will display all the names from the column separated by new lines in the view.
 

Similar threads

Back
Top