Good content takes time and effort to come up with.
Please consider supporting us by just disabling your AD BLOCKER and reloading this page again.
Hello fellas! Today is a big day for the Laravel community as Laravel 8 has released early access to the documentation. Though the features are still on their way to update, there are tons of loaded features to give it a try.
Make sure you have the following Laravel 8 requirements installed
composer create-project --prefer-dist laravel/laravel blog
Serve
Autoreload If Any ChangesIn earlier versions of Laravel if you made any changes to .env
files then you had to manually stop
and start the server
.
In the newer versions of Laravel as soon as you make any changes to the .env
file, it's automatically detected and the server is reloaded by Laravel.
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', 'TestController@index');
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\TestController;
Route::get('/', [TestController::class, 'index']);
In earlier versions of Laravel the models used to be under the App
namespace. I personally used to create an app/Models
directory and would put all my models in that folder.
In the newer version of Laravel, we have an app/Models
directory by default.
We just had a normal plain PHP files under database/factories
directory
Eloquent model factories have been entirely re-written as class-based factories.
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
}
}
use App\Models\User;
User::factory()->count(50)->create();
Similar to the older factory states but now inside the factory classes.
/**
* Indicate that the user is suspended.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function suspended()
{
return $this->state([
'account_status' => 'suspended',
]);
}
startingValue
)Soon we will be having startingValue
to it as a starting id value in our database.
Eg: When you create new orders for customers and they don't want to know they were the first ones. LOL
public function up() {
Schema::create('Orders', function(Blueprint $table){
$table->id()->startingValue('1000');
...
When you have a large Laravel application you migrations might grow over the time and start flooding like anything.
Now you can squash many migrations files into 1 migration file, which will then get saved inside the database/schema
directory.
php artisan schema:dump
// Dump the current database schema and prune all existing migrations...
php artisan schema:dump --prune
After squashing when you run the migration then first the database/schema
migrations will run, then database/migrations
directory migrations.
After performing a batch of jobs you can perform some other stuff.
The new batch
method of the Bus facade
may be used to dispatch a batch of jobs. Of course, batching is primarily useful when combined with completion callbacks. So, you may use the then
, catch
, and finally
methods to define completion callbacks for the batch. Each of these callbacks will receive an Illuminate\Bus\Batch
instance when they are invoked:
use App\Jobs\ProcessPodcast;
use App\Podcast;
use Illuminate\Bus\Batch;
use Illuminate\Support\Facades\Batch;
use Throwable;
$batch = Bus::batch([
new ProcessPodcast(Podcast::find(1)),
new ProcessPodcast(Podcast::find(2)),
new ProcessPodcast(Podcast::find(3)),
new ProcessPodcast(Podcast::find(4)),
new ProcessPodcast(Podcast::find(5)),
])->then(function (Batch $batch) {
// All jobs completed successfully...
})->catch(function (Batch $batch, Throwable $e) {
// First batch job failure detected...
})->finally(function (Batch $batch) {
// The batch has finished executing...
})->dispatch();
return $batch->id;
Rate limiters are defined using the RateLimiter
facades for
method. The for
method accepts a rate limiter name and a Closure that returns the limit configuration that should apply to routes that are assigned this rate limiter:
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::for('global', function (Request $request) {
return Limit::perMinute(1000);
});
Since rate limiter callbacks receive the incoming HTTP request instance, you may build the appropriate rate limit dynamically based on the incoming request or authenticated user:
RateLimiter::for('uploads', function (Request $request) {
return $request->user()->vipCustomer()
? Limit::none()
: Limit::perMinute(100);
});
The Laravel paginator has been updated to use the Tailwind CSS framework by default.
Laravel Jetstream is a beautifully designed application scaffolding for Laravel. Jetstream provides the perfect starting point for your next project and includes login, registration, email verification, two-factor authentication, session management, API support via Laravel Sanctum, and optional team management.
Jetstream is designed using Tailwind CSS and offers your choice of Livewire or Inertia scaffolding.
I hope this article helped you. Please share it with your friends.
Send Email In PHP With PHPMailer
Securely SSH Your Server & Push Files With FileZilla
Proper Way To Validate MIME Type Of Files While Handling File Uploads In PHP
Install Packages Parallel For Faster Development In Composer
Install RabbitMQ with Docker & Running with NodeJS
Basic Server Security Setup For Ubuntu / Linux
Sass or SCSS @function vs @mixin
NGINX Security Best Practices & Optimization
PHP Built-In Web Server & Testing Your Development Project In Mobile Without Any Software
Foreign Key Migrations Simplified In Laravel 7.x
Global Data In All Laravel Blade Pages
Debugging Laravel Queue Email Issues