1-) Найти

// You can specify the columns you need
// in when you use the find method on a model
User::find(‘id’, [‘email’,’name’]);

// You can increment or decrement 
// a field in your model

// Increment or decrement by one
Product::find($productId)->increment(‘views’);
Product::find($productId)->decrement(‘views’);
// You can also specify an amount
Product::find($productId)->increment(‘views’, 5);
Product::find($productId)->decrement(‘views’, 5);

2-) Обмен

Str::macro(‘swap’, function($map, $subject){
 return str_replace(array_keys($map), array_values($map), $subject);
});
$subject= ‘This post created by Bayram ek’;
echo Str::swap([
‘post’ => ‘code’,
‘ek’ => ‘Eker’
], $subject);
// This code created by Bayram Eker

3-) Цикл Foreach $

foreach($users as $user){
if($loop->first){
// This is the first iteration
}
if($loop->last){
// This is the last iteration
}}

4-) Группы маршрутов контроллера

Route::controller(OrderController::class)->group(function () {
   Route::get(‘/orders/{id}’, ‘show’);
   Route::post(‘/orders’, ‘store’);
});

Бонус: проверено и выбрано

// Checkbox
<input type=”Checkbox”
 name=”active”
 value=”active”
 @checked(old(‘avctive’, $user->active)) />
// Select
<select name=”version”>
   @foreach ($prdoct->versions as $version)
     <option value=”{{ $version }}” @selected(old(‘version’) ==     $version>
 {{ $version }}
     </option>
    @endforeach
</select>

Спасибо, что прочитали эту статью.

Если вы найдете эту статью полезной, пожалуйста, поделитесь ею в своей сети и не стесняйтесь использовать раздел комментариев для вопросов, ответов и предложений.

Вам также могут понравиться: