older and file structure of laravel
iam using visual strudio is idm and some body using phpstorm
folder structure of laravel
app -> console -> kernel.php
when we start laravel
it ist check kernel.php
php artisan serve- its ready made command
but if we need any thing custom command
it is available in app/commands foler
php artisan serve - deault command
app-> exceptions -> handler.php -> angual
if we got a error , we willnot show directly we have to show in a way which everyone underttand easily
app-?http-> controllers and middle ware
mvc -> model view controller
middlwware -> middle or mediator betwqen requesta nd controller
app->http->kernel.php
if we create any middle ware, we will register on this kernel.php
model
$this defines model
to comunicate betwen controller and databse -> model is mediator
In Laravel, a model is a class that represents a database table. It is a part of the Laravel's Eloquent ORM, which provides an easy and intuitive way to interact with databases using object-oriented programming techniques.
A model class in Laravel typically extends the Illuminate\Database\Eloquent\Model
base class and defines a connection to a specific database table. The model class provides methods to query the database table and perform CRUD (Create, Read, Update, Delete) operations.
Here's an example of a simple model class in Laravel:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class User extends Model { protected $fillable = ['name', 'email', 'password']; public function posts() { return $this->hasMany(Post::class); } }
In this example, we have a User
model class that extends the Model
base class. The $fillable
property is used to specify the columns that can be mass-assigned during creation or updating of a user record. The posts()
method defines a relationship between the User
model and the Post
model, specifying that a user has many posts.
With this model class, we can perform database queries and CRUD operations using methods such as all()
, find()
, create()
, and update()
, as well as relationships such as hasMany()
and belongsTo()
.
For example, we can retrieve all users from the database using:]
$users = User::all();
$user = User::find(1);
$user = User::find(1);
In Laravel, a model is a class that represents a database table. It is a part of the Laravel's Eloquent ORM, which provides an easy and intuitive way to interact with databases using object-oriented programming techniques.
A model class in Laravel typically extends the Illuminate\Database\Eloquent\Model
base class and defines a connection to a specific database table. The model class provides methods to query the database table and perform CRUD (Create, Read, Update, Delete) operations.
Here's an example of a simple model class in Laravel:
php<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $fillable = ['name', 'email', 'password'];
public function posts()
{
return $this->hasMany(Post::class);
}
}
In this example, we have a User
model class that extends the Model
base class. The $fillable
property is used to specify the columns that can be mass-assigned during creation or updating of a user record. The posts()
method defines a relationship between the User
model and the Post
model, specifying that a user has many posts.
With this model class, we can perform database queries and CRUD operations using methods such as all()
, find()
, create()
, and update()
, as well as relationships such as hasMany()
and belongsTo()
.
For example, we can retrieve all users from the database using:
php$users = User::all();
Or we can retrieve a single user by their ID using:
php$user = User::find(1);
We can also create a new user record using:
$user = User::create([ 'name' => 'John Doe', 'email' => 'john@example.com', 'password' => bcrypt('password') ]);
And we can update an existing user record using:
php$user = User::find(1);
$user->name = 'Jane Doe';
$user->save();
In summary, a model in Laravel is a class that represents a database table and provides methods to interact with it using object-oriented programming techniques. Models in Laravel are a core part of the Eloquent ORM and provide a powerful and flexible way to interact with databases.
app-> providers
appserviceprovider -> if we need a variabel used total application we can define at this place
used to
In Laravel, a provider is a class that performs various tasks during the application's bootstrapping process, such as registering services, bindings, and middleware.
More specifically, a provider in Laravel has the following responsibilities:
Registering services: A provider can register services with the Laravel's service container, which allows other parts of the application to access those services through dependency injection. This is typically done by defining bindings between interfaces and their implementations.
Registering middleware: A provider can register middleware that will be executed during the application's request lifecycle. Middleware can be used to modify incoming requests, modify responses, and perform other tasks.
Registering views and assets: A provider can also register views and assets, such as JavaScript and CSS files, that are used by the application's views and layouts.
Defining routes: A provider can define routes that the application will respond to. This can be useful for providing API endpoints, defining custom routes for authentication, or other purposes.
Bootstrapping: A provider's boot method is called after all other providers have been registered, and can be used to perform additional initialization and configuration tasks.
Laravel includes several built-in providers for common tasks, such as the RouteServiceProvider for defining routes, the EventServiceProvider for registering event listeners and subscribers, and the AppServiceProvider for registering bindings and other application-level services.
Developers can also create their own providers by extending the ServiceProvider class, and registering them in the app.php configuration file.
In summary, providers in Laravel are responsible for registering services, middleware, views, assets, and routes, and performing other initialization tasks during the application's bootstrapping process. They provide a way to modularize and organize application code, and make it easier to manage complex dependencies and configurations.
https://www.youtube.com/watch?v=J-C58vp1XrE&list=PLJlg6RBt94MG7UygN6gE1UHGWBHr4lJqi&index=8
No comments:
Post a Comment