1623400548
In today’s video we will talk about 15 Laravel Tips for Teamwork. How to make life of your teammates more pleasant?
00:00 Quick Intro
00:18 .env and .env.example
02:10 .env() only in config
03:33 Identical PHP Versions
04:51 Do NOT edit old migrations
06:07 Use Seeders
07:54 Code Standards and Styles
10:45 Careful with “composer update”
12:46 Use translations everywhere
13:28 Use Laravel Debugbar (or similar)
15:19 How your code will be used?
16:25 Tests should exist and be “green”
18:01 Use $fillable in Models
19:07 Middleware in Routes file
20:00 Use Form Requests
Subscribe: https://www.youtube.com/channel/UCTuplgOBi6tJIlesIboymGA/featured
#laravel
1595220000
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
1627131600
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
1619518440
Welcome to my Blog , In this article, you are going to learn the top 10 python tips and tricks.
…
#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
1595429220
Microsoft Teams is a communication platform used for Chat, Calling, Meetings, and Collaboration. Generally, it is used by companies and individuals working on projects. However, Microsoft Teams is available for macOS, Windows, and Linux operating systems available now.
In this tutorial, we will show you how to install Microsoft Teams on Ubuntu 20.04 machine. By default, Microsoft Teams package is not available in the Ubuntu default repository. However we will show you 2 methods to install Teams by downloading the Debian package from their official website, or by adding the Microsoft repository.
01- First, navigate to teams app downloads page and grab the Debian binary installer. You can simply obtain the URL and pull the binary using wget
;
$ VERSION=1.3.00.5153
$ wget https://packages.microsoft.com/repos/ms-teams/pool/main/t/teams/teams_${VERSION}_amd64.deb
#linux #ubuntu #install microsoft teams on ubuntu #install teams ubuntu #microsoft teams #teams #teams download ubuntu #teams install ubuntu #ubuntu install microsoft teams #uninstall teams ubuntu
1595201363
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'
];
}
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