Learn laravel php framework

Laravel Tutorial

This Laravel tutorial series describes the various features of Laravel and guides you to learn the Laravel PHP framework to make web development easier.

Web application development should be creative and enjoyable to fulfill the user experience realistically. Nowadays, users need more workability functionality in web pages. Because developers tend to develop complex websites and web applications, it usually takes a lot of time and a hassle to start building from scratch. So a new PHP framework has been introduced to make developers’ tasks more manageable. This tutorial will teach you about Laravel, an open-source PHP framework.

Required Knowledge

  • PHP: Laravel is built on top of the PHP programming language, so having a solid understanding of PHP is essential. This includes concepts such as variables, arrays, loops, functions, and object-oriented programming. If you want to learn PHP, please visit our PHP Tutorial.
  • HTML and CSS: Laravel is a web application framework, so you’ll need to have a basic understanding of HTML and CSS to build the front end of your application.
  • SQL: Laravel uses a database to store and retrieve data, so you’ll need to have a basic understanding of SQL and how to interact with a database using PHP.
  • MVC architecture: Laravel follows the model-view-controller (MVC) architectural pattern, which divides an application into three separate components: the model, the view, and the controller. It’s important to understand the role of each component in an MVC application.
  • Composer: PHP Composer is a dependency management tool for PHP. Laravel uses Composer to manage its dependencies, so you’ll need to be familiar with how to use Composer to install and update packages.
  • Git: Laravel uses Git for version control, so it’s helpful to have a basic understanding of how to use Git to track changes to your codebase.
  • Basic Linux commands: Laravel is typically deployed to a Linux server, so having a basic understanding of Linux commands will be helpful when setting up and managing your Laravel application.
Читайте также:  Проверка ajax запрос php

It is also good to have a general understanding of web development concepts and techniques, such as HTTP, routing, and security.

Источник

01. Introduction

Welcome to the Laravel Bootcamp! In this guide we will walk through building a modern Laravel application from scratch. To explore the framework, we’ll build a microblogging platform called Chirper.

#Choose your own adventure:
Blade or JavaScript

Laravel is incredibly flexible, allowing you to build your front-end with a wide variety of technologies to suit your needs. For this tutorial, we have prepared a few choices for you.

#Blade

Blade is the simple, yet powerful templating engine that is included with Laravel. Your HTML will be rendered server-side, making it a breeze to include dynamic content from your database. We’ll also be using Tailwind CSS to make it look great! If you’re not sure where to start, we think Blade is the most straight-forward. You can always come back and build Chirper again using JavaScript.

 
Greetings $friend >>, let's build Chirper with Blade!

#JavaScript & Inertia

If you’d like to use JavaScript, we will be providing code samples for both Vue and React. We’ll also be using Inertia to connect it all up and Tailwind CSS to make it look great! If you’re not sure which to select, we’re big fans of Vue since it is beginner-friendly and extremely powerful. After you’ve finished the Bootcamp, you can always try it again with the other stack. Go ahead and choose your stack:

 
template>
Welcome>
Hey >, let's build Chirper with Vue!
Welcome>
template>
 
Welcome>
Nice to see you friend>, let's build Chirper with React!
Welcome>

At any point you may view the code for either framework to see what life is like on the other side, just be sure not to mix the code in your project. Build Chirper with JavaScript and Inertia

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in most web projects.

Laravel is a Trademark of Taylor Otwell. Copyright © Laravel LLC.

Code highlighting provided by Torchlight

Источник

The PHP Framework
for Web Artisans

Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.

St. Jude The New York Times Warner Bros twitch About You Disney Bankrate WWE

Write code for the joy of it.

Laravel values beauty. We love clean code just as much as you do. Simple, elegant syntax puts amazing functionality at your fingertips. Every feature has been thoughtfully considered to provide a wonderful developer experience. Start Learning

One Framework, Many Flavors

Build robust, full-stack applications in PHP using Laravel and Livewire. Love JavaScript? Build a monolithic React or Vue driven frontend by pairing Laravel with Inertia. Or, let Laravel serve as a robust backend API for your Next.js application, mobile application, or other frontend. Either way, our starter kits will have you productive in minutes. Empower Your Frontend

Everything you need to be amazing.

Out of the box, Laravel has elegant solutions for the common features needed by all modern web applications. It’s time to start building amazing applications and stop wasting time searching for packages and reinventing the wheel.

Authentication

Authenticating users is as simple as adding an authentication middleware to your Laravel route definition:

 
Route::get('/profile', ProfileController::class)
->middleware('auth');
 
use Illuminate\Support\Facades\Auth;
// Get the currently authenticated user.
$user = Auth::user();

Of course, you may define your own authentication middleware, allowing you to customize the authentication process. For more information on Laravel’s authentication features, check out the authentication documentation.

Authorization

You’ll often need to check whether an authenticated user is authorized to perform a specific action. Laravel’s model policies make it a breeze:

 
php artisan make:policy UserPolicy

Once you’ve defined your authorization rules in the generated policy class, you can authorize the user’s request in your controller methods:

 
public function update(Request $request, Invoice $invoice)
Gate::authorize('update', $invoice);
$invoice->update(/* . */);
>

Eloquent ORM

Scared of databases? Don’t be. Laravel’s Eloquent ORM makes it painless to interact with your application’s data, and models, migrations, and relationships can be quickly scaffolded:

 
php artisan make:model Invoice --migration

Once you’ve defined your model structure and relationships, you can interact with your database using Eloquent’s powerful, expressive syntax:

 
// Create a related model.
$user->invoices()->create(['amount' => 100]);
// Update a model.
$invoice->update(['amount' => 200]);
// Retrieve models.
$invoices = Invoice::unpaid()->where('amount', '>=', 100)->get();
// Rich API for model interactions.
$invoices->each->pay();

Database Migrations

Migrations are like version control for your database, allowing your team to define and share your application’s database schema definition:

 
public function up(): void
Schema::create('flights', function (Blueprint $table)
$table->uuid()->primary();
$table->foreignUuid('airline_id')->constrained();
$table->string('name');
$table->timestamps();
>);
>

Validation

Laravel has over 90 powerful, built-in validation rules and, using Laravel Precognition, can provide live validation on your frontend:

 
public function update(Request $request)
$validated = $request->validate([
'email' => 'required|email|unique:users',
'password' => Password::required()->min(8)->uncompromised(),
]);
$request->user()->update($validated);
>

Notifications & Mail

Use Laravel to quickly send beautifully styled notifications to your users via email, Slack, SMS, in-app, and more:

 
php artisan make:notification InvoicePaid

Once you have generated a notification, you can easily send the message to one of your application’s users:

 
$user->notify(new InvoicePaid($invoice));

File Storage

Laravel provides a robust filesystem abstraction layer, providing a single, unified API for interacting with local filesystems and cloud based filesystems like Amazon S3:

 
$path = $request->file('avatar')->store('s3');

Regardless of where your files are stored, interact with them using Laravel’s simple, elegant syntax:

 
$content = Storage::get('photo.jpg');
Storage::put('photo.jpg', $content);

Job Queues

 
$podcast = Podcast::create(/* . */);
ProcessPodcast::dispatch($podcast)->onQueue('podcasts');
 
php artisan queue:work redis --queue=podcasts

Task Scheduling

Schedule recurring jobs and commands with an expressive syntax and say goodbye to complicated configuration files:

 
$schedule->job(NotifySubscribers::class)->hourly();

Laravel’s scheduler can even handle multiple servers and offers built-in overlap prevention:

 
$schedule->job(NotifySubscribers::class)
->dailyAt('9:00')
->onOneServer();
->withoutOverlapping();

Testing

Laravel is built for testing. From unit tests to browser tests, you’ll feel more confident in deploying your application:

 
$user = User::factory()->create();
$this->browse(fn (Browser $browser) => $browser
->visit('/login')
->type('email', $user->email)
->type('password', 'password')
->press('Login')
->assertPathIs('/home')
->assertSee("Welcome $user->name>")
);

Events & WebSockets

Laravel’s events allow you to send and listen for events across your application, and listeners can easily be dispatched to a background queue:

 
OrderShipped::dispatch($order);
 
class SendShipmentNotification implements ShouldQueue
public function handle(OrderShipped $event): void
// .
>
>

Your frontend application can even subscribe to your Laravel events using Laravel Echo and WebSockets, allowing you to build real-time, dynamic applications:

 
Echo.private(`orders.$orderId>`)
.listen('OrderShipped', (e) =>
console.log(e.order);
>);

We’ve just scratched the surface. Laravel has you covered for everything you will need to build a web application, including email verification, rate limiting, and custom console commands. Check out the Laravel documentation to keep learning.

Источник

Оцените статью