Ruthie  Blanda

Ruthie Blanda

1627021260

9 Quick Tips about Laravel Blade

I decided to compile quick things I’ve learned over my Laravel career about Blade views and templates, here’s my list.

00:00 Intro
00:13 @forelse Loop
00:44 @auth and @guest
01:21 auth()-user() Object
02:03 Format Carbon Dates
02:48 Route::view()
03:19 Blade Error Pages
04:13 Artisan view:clear
05:00 asset() helper
06:12 Meta Title

#laravel blade #laravel

What is GEEK

Buddha Community

9 Quick Tips about Laravel Blade
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

Ruthie  Blanda

Ruthie Blanda

1627021260

9 Quick Tips about Laravel Blade

I decided to compile quick things I’ve learned over my Laravel career about Blade views and templates, here’s my list.

00:00 Intro
00:13 @forelse Loop
00:44 @auth and @guest
01:21 auth()-user() Object
02:03 Format Carbon Dates
02:48 Route::view()
03:19 Blade Error Pages
04:13 Artisan view:clear
05:00 asset() helper
06:12 Meta Title

#laravel blade #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

Ida  Nader

Ida Nader

1594168098

[Lesson 15] Laravel Blade Foreach ✅ (Laravel 7: Posts Index & Show Views)

Laravel Blade Foreach ✅ Lesson 15


In this lesson, we will pass the posts we created in previous lessons to our posts.index view & our posts.show views.

Using Laravel's @foreach blade directive, we will iterate over each one of our posts and properly output the content for each.

Once we have completed our Posts index view, we will set up each post to on our index page to link to its individual "show" page -- by the end of this lesson we will have completed two of our resourceful routes for our posts we created in earlier lessons.

Dive in, as we check out the power of Laravel Blade Foreach Loops as well as everything else that happens to be incredible about Laravel.

#laravel #laravel blade #laravel blade foreach