@foreach ($users as $user)
@if ($loop->first)
This is the first iteration.
@endif
@if ($loop->last)
This is the last iteration.
@endif
<p>This is user {{ $user->id }}</p>
@endforeach
// Instead of this
Route::get('about', 'TextsController@about');
// And this
class TextsController extends Controller
{
public function about()
{
return view('texts.about');
}
}
// Do this
Route::view('about', 'texts.about');
@if(auth()->user())
// The user is authenticated.
@endif
@auth
// The user is authenticated.
@endauth
@guest
// The user is not authenticated.
@endguest
@foreach ($users as $user)
@foreach ($user->posts as $post)
@if ($loop->parent->first)
This is first iteration of the parent loop.
@endif
@endforeach
@endforeach
<textarea>@br2nl($post->post_text)</textarea>
public function boot()
{
Blade::directive('br2nl', function ($string) {
return "<?php echo preg_replace('/\<br(\s*)?\/?\>/i', \"\n\", $string); ?>";
});
}
// Using include, the old way
@include("components.post", ["title" => $post->title])
// Using Blade-X
<x-post link="{{ $post->title }}" />
// Using Blade-X variable binding
<x-post :link="$post->title" />