iJamesPHP iJamesPHP - 2 years ago 94
SQL Question

Include new lines within SQL VARCHAR?

On my site, users can set a profile description which is displayed on their profile page. When they update it I want it to include line breaks.

For example, currently:

"Hey there!
My name's James :)"

Is saved as "Hey there! My name's James :)"

How can I get it to include the line breaks?

Here's my code by the way:



namespace EG\Http\Controllers;

use Auth;
use Illuminate\Http\Request;
use EG\Models\User;

class ProfileController extends Controller
public function getProfile($username)
$user = User::where('username', $username)->first();

if (!$user) {

return view('profile.index')
->with('user', $user);

public function getEdit()
return view('profile.edit');
public function postEdit(Request $request)
$this->validate($request, [
'about' => 'max:250|min:2',
'twitter' => 'alpha_dash|max:15',
'xbl' => 'max:16',
'psn' => 'max:16',
'esea' => 'numeric',
'twitch' => 'alpha_dash|max:25',

'description' => $request->input('about'),
'twitter' => $request->input('twitter'),
'xbl' => $request->input('xbl'),
'psn' => $request->input('psn'),
'esea' => $request->input('esea'),
'twitch' => $request->input('twitch'),

return redirect()->route('profile.edit')
->with('info', 'Your profile has been updated!')
->with('info_type', 'success');


Answer Source

You can convert \n line breaks to <br> using nl2br when you print the text in an HTML document.

For example create a function in the user model.

function getDescriptionHTML(){
    return nl2br($this->description);

And in the view.

{!! $user->getDescriptionHTML() !!}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download