Laravel Tip and Tricks: Foreach Loop Tricks You Might Not Know

Laravel in Practice Episode 1:

In this video, I will show you some tricks you might not know when working with loops in Laravel blade templates. You will learn how to use the $loop variable to access the different properties of the current loop iteration. I will also explain to you how you can use the forelse method instead of the combination of if and foreach when checking for empty states.

 

#laravel 

What is GEEK

Buddha Community

Laravel Tip and Tricks: Foreach Loop Tricks You Might Not Know
Ray  Patel

Ray Patel

1619518440

top 30 Python Tips and Tricks for Beginners

Welcome to my Blog , In this article, you are going to learn the top 10 python tips and tricks.

1) swap two numbers.

2) Reversing a string in Python.

3) Create a single string from all the elements in list.

4) Chaining Of Comparison Operators.

5) Print The File Path Of Imported Modules.

6) Return Multiple Values From Functions.

7) Find The Most Frequent Value In A List.

8) Check The Memory Usage Of An Object.

#python #python hacks tricks #python learning tips #python programming tricks #python tips #python tips and tricks #python tips and tricks advanced #python tips and tricks for beginners #python tips tricks and techniques #python tutorial #tips and tricks in python #tips to learn python #top 30 python tips and tricks for beginners

Seamus  Quitzon

Seamus Quitzon

1595220000

10 Laravel Quick Tips

Tip 1. Controllers Having Single Action

In some situations you need a single action in a controller, if this is the case in Laravel you can achieve it by **__invoke()** method.

<?php

namespace App\Http\Controllers;
use App\User;
use App\Http\Controllers\Controller;

class ShowProfile extends Controller
{
   /**
   * Show the profile for the given user.
   *
   * @param int $id
   * @return Response
   */
    public function __invoke($id)
    {
         return view('user.profile', ['user' => User::findOrFail($id)]);
    }
}

Routes:

Route::get('user/{id}', 'ShowProfile');

Artisan command to generate this controller:

php artisan make:controller ShowProfile --invokable

Tip 2. Migration Fields Having Timezone

Do you know in Laravel migrations are just not limited to **timestamps()** you can also add **timestampsTz()**

Schema::create('employees', function (Blueprint $table) {
 $table->increments('id');
 $table->string('name');
 $table->string('email');
 $table->timestampsTz();
});

Also, there are columns **dateTimeTz()** , **timeTz()** , **timestampTz()****softDeletesTz()**.

Tip 3. Eloquent has() deeper

You can use Eloquent has() function to query relationships even two layers deep!

// Author -> hasMany(Book::class);
// Book -> hasMany(Rating::class);
$authors = Author::has('books.ratings')->get();

Tip 4. SoftDeletes: Restore Multiple

To restore soft deleted rows, you can restore them in one sentence.

User::withTrashed()->where('author_id', 1)->restore();

Tip 5. Image Validation

During image upload, validate images on specific dimensions.

'photo' => 'dimensions:max_width=4096,max_height=4096'

Tip 6. Wildcard Subdomains

You can create route group by dynamic subdomain name, and pass its value to every route.

Route::domain('{username}.workspace.com')->group(function () {
 Route::get('user/{id}', function ($username, $id) {
 //
 });
});

#laravel #php #laravel quick tips #laravel tips #laravel tutorials #laravel tuts

Seamus  Quitzon

Seamus Quitzon

1595201363

Php how to delete multiple rows through checkbox using ajax in laravel

First thing, we will need a table and i am creating products table for this example. So run the following query to create table.

CREATE TABLE `products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Next, we will need to insert some dummy records in this table that will be deleted.

INSERT INTO `products` (`name`, `description`) VALUES

('Test product 1', 'Product description example1'),

('Test product 2', 'Product description example2'),

('Test product 3', 'Product description example3'),

('Test product 4', 'Product description example4'),

('Test product 5', 'Product description example5');

Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = [
        'name','description'
    ];
}

Step 2: Create Route

Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.

routes/web.php

Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);

#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete

Laravel Tip and Tricks: Foreach Loop Tricks You Might Not Know

Laravel in Practice Episode 1:

In this video, I will show you some tricks you might not know when working with loops in Laravel blade templates. You will learn how to use the $loop variable to access the different properties of the current loop iteration. I will also explain to you how you can use the forelse method instead of the combination of if and foreach when checking for empty states.

 

#laravel 

Ruthie  Blanda

Ruthie Blanda

1627131600

Tips for Working in Dev-Team. Part 1: 5 Non-Laravel Tips

A mini-series of tips around working in a team effectively. In this first part, I talk about things that are (almost) not related to Laravel projects specifically.

#non-laravel tips #laravel tips #laravel