0% found this document useful (0 votes)
26 views

Laravel Part-2

Uploaded by

waver58650
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Laravel Part-2

Uploaded by

waver58650
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Video-12 (Laravel directory structure):-

-----------------------------------------------------
1. app folder :- The app directory contains the core code of your application.

2. bootstrap folder :- The bootstrap directory contains the app.php file


which bootstraps the framework.

3. config folder:- The config directory, as the name implies, contains all of
your application's configuration files.

4. database folder :- The database directory contains your database


migrations, model factories, and seeds. If you wish, you may also use this
directory to hold an SQLite database.

5. public folder :- The public directory contains the index.php file, which
is the entry point for all requests entering your application and configures
autoloading. This directory also houses your assets such as images,
JavaScript, and CSS.

6. resources folder :- The resources directory contains your views as well


as your raw, un-compiled assets such as CSS or JavaScript.This directory
also houses all of your language files.

7. routes folder :- The routes directory contains all of the route definitions
for your application.

8. storage folder:- The storage directory contains your compiled Blade


templates, file based sessions, file caches, and other files generated by
the framework.

9. tests folder:- The tests directory contains your automated tests.

10. vendor folder :- The vendor directory contains your Composer


dependencies.

1. app Directory:-
a. Console folder :- The Console directory contains all of the custom
Artisan commands for your application.
b. Exception folder :- The Exceptions directory contains your
application's exception handler and is also a good place to place any
exceptions thrown by your application.

c. Http folder :- The Http directory contains your controllers,


middleware, and form requests.
1. Controllers folder:- It contains all container files.
2. Middleware folder:- It contains all middleware files.

d. Models folder :- The model directory contains all of your Eloquent


classes.

e. Providers folder :- The Providers directory contains all of the service


providers for your application.

2. bootstrap folder:-
a. cache folder :- The cache directory which contains framework
generated files for performance optimization such as the route and
services cache files.

3. config folder:-

4. database folder:-
a. factories folder :- It contains model factories.
b. migrations folder :- It contains migrations factories.
c. seeders folder :- It contains seeders factories.

5. public folder:-
a. css folder
b. images folder
c. js folder

6. resources folder:-
a. css folder :- It contains uncompiled css.
b. js folder :- It contains uncompiled js.
c. lang folder :- It contains a language file.
d. views folder :- It contains all blade files.
7. routes folder:-
a. api.php :- The api.php file contains routes that the
RouteServiceProvider places in the api middleware group, which
provides rate limiting. These routes are intended to be stateless, so
requests entering the application through these routes are intended to be
authenticated via tokens and will not have access to session state.

b. channel.php :- The channels.php file is where you may register all of


the event broadcasting channels that your application supports.

c. console.php :- The console.php file is where you may define all of your
Closure based console commands. Each Closure is bound to a command
instance allowing a simple approach to interacting with each command's
IO methods. Even though this file does not define HTTP routes, it defines
console based entry points (routes) into your application.

d. web.php :- The web.php file contains routes that the RouteService


Provider places in the web middleware group, which provides session
state, CSRF protection, and cookie encryption. If your application does not
offer a stateless, RESTful API, all of your routes will most likely be defined
in the web.php file.

8. storage folder:-
a. app folder :- The app directory may be used to store any files generated by
your applications.
i. public folder :- The storage/app/public directory may be used
to store user-generated files, such as profile avatars, that should be
publicly accessible.

b. framework folder:- The framework directory is used to store framework


generated files and cache.

c. logs folder :- The logs directory contains your application’s log files.

Video-13 (Routes in laravel):-


-----------------------------------------
1. All Laravel routes are defined in your route files, which are located in the
routes directory. These files are automatically loaded by the framework.

2. The routes/web.php file defines routes that are for your web interface.

3. For most applications, you will begin by defining routes in your


routes/web.php file.

Syntax:-
Route::get(‘URI’,Closure/Callback)
Here,
a. Route – class
b. :: – scope resolution
c. get – method

Example:-
Route::get(‘about’, function(){
return ‘’Hello World”;
});

Route Returning string :-


Syntax:-
Route::get(‘URI’,Closure/Callback)
Here,
d. Route – class
e. :: – scope resolution
f. get – method

Example:-
Route::get(‘about’, function(){
return ‘’Hello World”;
});

1. Route Parameters :-
Sometimes you will need to capture segments of the URI within your
route. For example, you may need to capture a user's ID from the URL.
Syntax:-
Route::get('uri/{p_para}', function ($para) {
return $para;
});

Example:-
Route::get(‘user/{u_id}’,function($id){
return $id;
});

2. Route Multiple Parameters :-


Example:-

Route::get(‘post/{post_id}/comment/{comment_id}’,function($post_id,$co
mment_id){
return $post.id.$comment.id;
});

Note:-
Route parameters are always encased within {} braces and should
consist of alphabetic characters, and may not contain a -character.

3. Optional routes Parameters :-


We can make optional parameters by placing a ? mark after the
parameter name.

Example:-
Route :: get(‘student/{name?}’, function ($name=null){
return $name;
});

Route :: get(‘student/{name?}’, function ($name=’sonam’){


return $name;
});

4. Route Parameter and Regular Expression :-


You may constrain the format of your route parameters using the where
method on a route instance. The where method accepts the name of the
parameter and a regular expression defining how the parameter should be
constrained:
Syntax:-
Route::get('uri/{p_para}', function ($para) {
return $para;
})->where(‘p_para’,’Regular Expression’);

Example:-
Route::get(product/{p_name}’,function($name){
return $name;
})->where(‘p_name’,’[A-Za-z]+’);

Route::get(manager/{id}{name}’,function($id,$name){
return $id.$name;
})->where([‘id’=>’[0-9]+’,’name’=>’[A-Za-z]+’]);

5. Route Parameter with Regular Expression Helper Method :-


Example:-
Route::get(manager/{id}{name}’,function($id,$name){
return $id.$name;
})->whereNumber(‘id’)->whereAlpha(‘name’);

Route::get('/user/{id}', function ($id) {


//
})->whereUuid('id');

Redirect Route :-
1. If you are defining a route that redirects to another URI, you may use the
Route::redirect method.
2. By default, Route::redirect returns a 302 status code.

Syntax:-
Route::redirect(‘/here’,’/there’);

Route::redirect(‘/here’,’/there’,301); //define status code


Route::permanentRedirect(‘/here’,’/there’);
Example:-
Route::redirect(‘/login-success’,’/dashboard’);

Fallback Route :-
1. Using the Route::fallback method, you may define a route that will
be executed when no other route matches the incoming request.

2. The fallback route should always be the last route registered by your
application.

Example:-
Route::fallback(function(){
//<h1> Page Not found<h1>
});

Route Methods :-
1. Route :: get(‘URI’ , ‘Callback’);
2. Route :: post(‘URI’ , ‘Callback’);
3. Route :: put(‘URI’ , ‘Callback’);
4. Route :: patch(‘URI’ , ‘Callback’);
5. Route :: delete(‘URI’ , ‘Callback’);
6. Route :: options(‘URI’ , ‘Callback’);

Using Multiple Methods :-


1. Route :: match([‘get’,’post’], ‘/’, function(){
//
});
2. Route :: any(‘/’ , function(){
//
});

You might also like