Reputation: 57
I've come across the @
symbol a couple of times in Blade templates. What does it do in laravel blade? Examples are shown below.
@method('DELETE') @CRSF @foreach @endforeach
Upvotes: 2
Views: 3083
Reputation: 1702
I know you are asking about Blade, but that isn't in the question and comments are transient. Moreover, other readers might find this looking for what the docblocks @
s are.
In a comment beginning with /**
before a class or function the @
sign signifies a directive to documentation tools like Doxygen or PHPDoc (I think, I've not used that one). The common directives there include @param
, @return
, @see
, @seealso
, @TODO
, @link
. An example would be
/**
* Function to do thing.
* @param int $foo A variable used in the function for reasons.
* @return A result of the thing done.
* @seealso Bar::fubar()
**/
As mentioned in other answers the @
symbol is the prefix for Blade "commands" called directives. The two you are asking about specifically are built into Laravel. The ones you're looking at are likely built in, but you can add directives to make your own for things you do/print often.
@method('DELETE')
- RESTful standard define request methods PATCH, and DELETE which are not part of the actual HTTP(S) standard. To emulate these unsupported methods a hidden field is added to forms in Laravel forms to tell the HTTP kernel what the request method is for matching methods for routing purposes. So @method('DELETE')
does something like (not exacatly, but you get the idea):
echo '<input type="hidden" name="method" value="DELETE" />';
@csrf
formerly @csrf_field
is a command to get a hidden input with the CSRF token. There is one to get just token, too -- @csrf_token
-- which is useful for ajax requests. @csrf does something like (but not exactly):
echo '<input type="hidden" name="_token" value="' . {$csrf_token() . '" />';
CSRF tokens are "nonce" (numbers used only once) that help to prevent Cross Site Request Forgery.
In the cached/compiled blade in storage/framework/views/
.
Upvotes: 4
Reputation: 2589
It is not a command that can be "translated" into PHP. @
is just a symbol, or more a prefix for the blade related keywords.
So the result of this blade:
@foreach($users as $user)
<li>{{ $user->name }}</li>
@endforeach
would be equal to this plain PHP:
foreach($users as $user) {
echo "<li>{$user->name}</li>";
}
Upvotes: 3
Reputation: 488
It means that you are using Blade directives. These are functions of the Laravel template engine.
Upvotes: 2