Laravel Part-2
Laravel Part-2
-----------------------------------------------------
1. app folder :- The app directory contains the core code of your application.
3. config folder:- The config directory, as the name implies, contains all of
your application's configuration files.
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.
7. routes folder :- The routes directory contains all of the route definitions
for your application.
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.
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.
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.
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.
c. logs folder :- The logs directory contains your application’s log files.
2. The routes/web.php file defines routes that are for your web interface.
Syntax:-
Route::get(‘URI’,Closure/Callback)
Here,
a. Route – class
b. :: – scope resolution
c. get – method
Example:-
Route::get(‘about’, function(){
return ‘’Hello World”;
});
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;
});
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.
Example:-
Route :: get(‘student/{name?}’, function ($name=null){
return $name;
});
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]+’]);
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’);
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’);