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

What is GEEK

Buddha Community

10 Laravel Quick Tips
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

Yogi Gurjar

1600307091

How to Install Laravel 8 on Windows 10 Xampp

How to install laravel 8 on windows 10. In this tutorial, i would love to share with you how to install laravel 8 on windows 10.

How to Install Laravel 8 on Windows 10 Xampp

Installing laravel 8 on windows 10 xampp server step by step:

  1. Step 1 – Prerequisiteto Install Composer On Windows
  2. Step 2 – Server Requirements For Laravel 8
  3. Step 3 – Installing Laravel On Windows 10 Xampp
  4. Step 4 – Start Development Server For Laravel 8

https://laratutorials.com/installing-laravel-8-on-windows-10-xampp/

#install laravel on windows xampp #how to install laravel in windows 10 xampp #install xampp on windows 10 laravel installation steps #laravel installation steps #how to run laravel project on localhost xampp

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

Juned Ghanchi

1621508419

Laravel App Development Company in India, Hire Laravel Developers

Hire our expert team of Laravel app developers for flexible PHP applications across various cloud service providers.

With this easy build technology, we develop feature-rich apps that make your complex business process a lot easier. Our apps are,

  • More secure and scalable.
  • A good framework lets you manage and organize resources better.
  • And have a rich community base.

Get your business a best in classlaravel app. Hire laravel app developers in India. We have the best organizational set-up to provide you the most advanced app development services.

#laravel app development company india #hire laravel developers india #laravel app development company #hire laravel developers #laravel development agency #laravel app programmers