in Education by
I am currently developing a recipe website with Laravel and I have run into an issue on my recipe show page (show individual recipe). The recipe show page displays the description, ingredients, and step-by-step instructions. Both my ingredients and step-by-step instructions are inserted into my DB as one string. The input form requests users to list each ingredient/step on an individual line. I then use the PHP function nl2br() to show the information as a list. However, I would very much like to have control of each new line, preferably be able to wrap an li around each line which I can later style in CSS. I found this link here on Stackoverflow: wrap new line variable with I believe this is what I'm looking for, however, I'm not sure how I would adjust this to Laravel. Currently I am using this line of code to retrieve the ingredients and step-by-step:

{!! nl2br(e($recipe->directions)) !!}

{!! nl2br(e($recipe->ingredients)) !!}

Any help on this would be very much appreciated as it is a little bit outside my current area of expertise! Let me know if I need to clarify this question a little more or provide you guys with some more context! Thank you so much! :) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Break the input into an array of lines by exploding the string by the new line escape. $lines = explode("\n", $recipe->directions); Output each line with elements:
    @foreach ($lines as $line)
  • {{$line}}
  • @endforeach

Related questions

0 votes
    I am currently developing a recipe website with Laravel and I have run into an issue on my recipe show ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I'm pretty new at laravel, in fact and I'm trying to create my very first project. for some ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I am using Laravel 5.7 version. I got the below error for users_activations table while run the command ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I am using Laravel 5.7 version. I got the below error for users_activations table while run the command ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I am using Laravel Image Intervention to resize an image upload field on my form. This is the error ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I want to submit some form information into my table, but this error is showing, if i do Route::resource('userinfo', ... can't insert data, what will be the solution. My controller...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    I want to submit some form information into my table, but this error is showing, if i do Route::resource('userinfo', ... can't insert data, what will be the solution. My controller...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    Can you arrange 9 numerals - 1, 2, 3, 4, 5, 6, 7, 8 and 9 [using each numeral just once] above and below a division line, to create a fraction equaling to 1/3 [one third]?...
asked Feb 13, 2021 in Education by JackTerrance
0 votes
    If a Siren sounds for every 5 seconds, how many times will it sound in ¾ of an hour? A) 541 times B) 540 times C) 450 times D) 275 times...
asked Feb 14, 2021 in Education by JackTerrance
0 votes
    New bitcoins are released every time a transaction is verified. A. True B. False...
asked Nov 30, 2022 in Education by JackTerrance
0 votes
    I created an list. When you select each , there will be active classes each. Now, my goal is how ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Calculate the binding energy per nucleon of L i L isotope, which has the isotopic mass of 7.016 a m u 7.016 . The ... .000548 a m u = . Select the correct answer from above options...
asked Jan 2, 2022 in Education by JackTerrance
0 votes
    I am trying to replace all characters that are not C, T, A or G with an N in the sequence part ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    It is Mandatory that the doctype declaration is the first line of every HTML5 Page. 1. True 2. False...
asked Apr 10, 2021 in Education by JackTerrance
0 votes
    I have 2 buckets prod and dev. Inside .env I have S3_PROD and S3_DEV. I want my system to point ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
...