Wednesday, May 11, 2022

Blade Template #3 | Extract partials + Paste a list of data

Extract Partial

  • Open app.blade.php.
  • Imagine you want to extract the below code into a navigational partial.
  • Cut out that exact part of the code from app file and create a new file under views named nav.blade.php.
  • Paste the code inside nav.
  • How to bring navigation inside app? Use a keyword: @include.
  • In app body part, write down @include('nav') :
  • Refreshing your browser will get you the exact same thing.
  • If you want to use the same navigation, simply include the keyword.

Paste a List of Data

  • For the routes, make sure to use controller as such:
  • Then in HelloController.php, make a fake variable (just to test):
  • Don't forget to add compact as the second string.
  • Then, in service.blade.php, we only need to use php:
  • For this method, you need to make sure service (the variable) actually exist.
  • If there is no content in function service (in controller), instead of using @foreach, we can use @forelse.
  • forelse allows us to add a new section which is @empty:
  • Whatever you put in between @empty and @endforelse will get output if there are no services.
  • You can put list item or paragraph that says "No services available".

End

No comments:

Post a Comment

Komen atau sebarang pertanyaan di sini :)

WordPress #3 | How to Change Website URL

Hi. Today we're gonna look at how to change your website URL in case you messed up. In this case, yes, I messed up. That is why this pos...